6 use File
::Temp qw
/tempfile/;
7 use Test
::More tests
=> 20;
9 our ($section_1, $section_2, $section_3, $section_4, %options);
12 my ($options, $description) = m/^(.*?)\n\n(.*)/s;
13 my (@options, $longest);
15 for my $option ($options =~ m/\G((?:-\w|--\w+))(?:,\s*)?/g) {
16 push @options, $option;
17 $longest = $option if length $option > length $longest
20 $options{$longest} = {
22 description
=> $description,
27 Pod
::Constants
->import(
28 section_1
=> \
$section_1,
30 section_2
=> \
$section_2,
31 section_3
=> sub { tr/[a-z]/[A-Z]/; $section_3 = $_ },
32 section_4
=> sub { eval },
33 'GUI parameters' => sub {
34 Pod
::Constants
::delete_hook
('*item')
36 'command line parameters' => sub {
37 Pod
::Constants
::add_hook
('*item' => \
&handle_item
)
41 use_ok
('Pod::Constants');
44 ok
$Pod::Constants
::VERSION
, "Pod::Constants sets its own VERSION";
47 if ( 0 ) { $Cheese::foo
= $ReEntrancyTest::wohoo
= $Cheese::quux
; }
50 is
($section_1, "Down with Pants!\n\n", "no trim from main");
51 is
($section_2, "42", "with trim from main");
52 is
($section_3, "CLANK_EST", "sub");
53 is
($section_4, "touche", "eval");
54 is
($Cheese::foo
, "detcepxe", "From module");
55 is
($ReEntrancyTest::wohoo
, "Re-entrancy works!", "From module");
56 is
($Cheese::quux
, "Blah.", "From module(2)");
57 like
(`$^X -c t/Cheese.pm 2>&1`, qr
/syntax OK
/, "perl -c module");
58 like
(`$^X -c t/cheese.pl 2>&1`, qr
/syntax OK
/, "perl -c script");
60 # test the examples on the man page :)
61 package Pod
::Constants
;
62 Pod
::Constants
->import (SYNOPSIS
=> sub {
63 $main::section_1
= join "\n", map { s/^ //; $_ } split /\n/, $_
67 # why define your test results when you can read them in from POD?
68 $section_1 =~ s/myhash\)/myhash, %myhash2)/;
69 $section_1 =~ s/myhash;/myhash, "%myhash\'s value after the above:" => sub { %myhash2 = eval };/;
71 my ($fh, $file) = tempfile
'pod-constants-testXXXX', TMPDIR
=> 1, UNLINK
=> 1;
79 $INC{'TestManPage.pm'} = $file;
82 is
$TestManPage::myvar
, 'This string will be loaded into $myvar',"man page example 1";
83 is
$TestManPage::VERSION
, $Pod::Constants
::VERSION
, "man page example 2";
84 ok
$TestManPage::VERSION
, "man page example 2 cross-check";
85 is
$TestManPage::myarray
[2], 'For example, this is $myarray[2].', "man page example 3";
88 while (my ($k, $v) = each %TestManPage::myhash
) {
89 if (exists $TestManPage::myhash2
{$k}) { $ok ++ };
90 if ($v eq $TestManPage::myhash2
{$k}) { $ok ++ };
93 is
$ok, 4, "man page example 4";
94 is
scalar keys %TestManPage::myhash
, 2, "man page example 4 cross-check";
95 is
$TestManPage::html
, '<p>This text will be in $html</p>', "man page example 5";
98 $TestManPage::myvar
= $TestManPage::html
= undef;
99 @TestManPage::myarray
= ();
101 is
$options{foo
}->{options
}->[0], "-f", "Pod::Constants::add_hook";
102 ok
!exists $options{gtk
}, 'Pod::Constants::remove_hook';
118 $section_4 = "touche"
122 =head1 command line parameters
124 the following command line parameters are supported
128 This does something cool.
132 This also does something pretty cool.
134 =head1 GUI parameters
136 the following GUI parameters are supported
140 Use a GTK+ look-and-feel
144 Use a Qt look-and-feel
This page took 0.030747 seconds and 4 git commands to generate.