| 1 | package Test::Pod::Content; | ||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use base qw(Pod::Simple Test::More); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 2 | ▶ | use Exporter; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 2 | ▶ | use version; our $VERSION = qv('0.0.6'); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 2 | our @EXPORT = qw(pod_section_is pod_section_like); | |||||||||||||
| 9 | |||||||||||||||
| 10 | # Globals for running a simple state machine | ||||||||||||||
| 11 | 2 | my $_state = q{}; | |||||||||||||
| 12 | 2 | my $_section = q{}; | |||||||||||||
| 13 | 2 | my $_content = q{}; | |||||||||||||
| 14 | 2 | my $_test_content_sub; | |||||||||||||
| 15 | |||||||||||||||
| 16 | # cleanup everything once we've run our test | ||||||||||||||
| 17 | 4 | ▶ | sub _reset { | ||||||||||||
|
Subroutine
_reset: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 4 | my $parser = shift; | |||||||||||||
| 19 | 4 | $_state = q{}; | |||||||||||||
| 20 | 4 | $_section = q{}; | |||||||||||||
| 21 | 4 | $_content = q{}; | |||||||||||||
| 22 | |||||||||||||||
| 23 | # source_dead is not reliable - just die to force terminating the | ||||||||||||||
| 24 | # parser run | ||||||||||||||
| 25 | 4 | $parser->source_dead(1); | |||||||||||||
| 26 | 4 | die "OK\n"; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | 1 | ▶ | sub pod_section_is { | ||||||||||||
|
Subroutine
pod_section_is: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||
| 30 | 1 | my ($name, $section, $content, $comment ) = @_; | |||||||||||||
| 31 | |||||||||||||||
| 32 | 1 | my $found = 0; | |||||||||||||
| 33 | |||||||||||||||
| 34 | 2 | ▶ | $_test_content_sub = sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 35 | 2 | my ($parser, $section_name, $test_content) = @_; | |||||||||||||
| 36 | 2 | ▶ | if ($section_name eq $section) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 1 | $found++; | |||||||||||||
| 38 | 1 | Test::More::is($test_content, $content, $comment); | |||||||||||||
| 39 | 1 | _reset($parser); | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | 1 | }; | |||||||||||||
| 42 | |||||||||||||||
| 43 | 1 | eval { Test::Pod::Content->filter( _find_file($name) ) }; | |||||||||||||
| 44 | 1 | ▶ | if ($@) { die $@ if ($@ !~m{^OK\n$}xm) }; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 45 | |||||||||||||||
| 46 | 1 | ▶ | if (not $found) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | 0 | Test::More::fail $comment; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | 1 | return; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 3 | ▶ | sub pod_section_like { | ||||||||||||
|
Subroutine
pod_section_like: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||
| 53 | 3 | my ($name, $section, $regex, $comment ) = @_; | |||||||||||||
| 54 | |||||||||||||||
| 55 | 3 | my $found = 0; | |||||||||||||
| 56 | |||||||||||||||
| 57 | 19 | ▶ | $_test_content_sub = sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 58 | 19 | my ($parser, $section_name, $test_content) = @_; | |||||||||||||
| 59 | 19 | ▶ | if ($section_name eq $section) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | 3 | $found++; | |||||||||||||
| 61 | 3 | Test::More::like($test_content, $regex, $comment); | |||||||||||||
| 62 | 3 | _reset($parser); | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | 3 | }; | |||||||||||||
| 65 | |||||||||||||||
| 66 | 3 | eval { Test::Pod::Content->filter( _find_file($name) ) }; | |||||||||||||
| 67 | 3 | ▶ | if ($@) { die $@ if ($@ !~m{^OK\n$}xm) }; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 68 | |||||||||||||||
| 69 | 3 | ▶ | if (not $found) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 70 | 0 | Test::More::fail $comment; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | 3 | return; | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 4 | ▶ | sub _find_file { | ||||||||||||
|
Subroutine
_find_file: called CC=6 SCAR=18.1
| |||||||||||||||
| 76 | 4 | my $name = shift; | |||||||||||||
| 77 | 4 | ▶ | return $name if (-e $name); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 78 | 4 | for my $path (@INC) { | |||||||||||||
| 79 | 23 | ▶ | return "$path/$name" if -e "$path/$name"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 80 | } | ||||||||||||||
| 81 | 2 | $name =~s{::}{/}xmg; | |||||||||||||
| 82 | 2 | $name .= '.pm'; | |||||||||||||
| 83 | 2 | for my $path (@INC) { | |||||||||||||
| 84 | 5 | ▶ | return "$path/$name" if -e "$path/$name"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 85 | } | ||||||||||||||
| 86 | 0 | return; | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | 76 | ▶ | sub _handle_element_start { | ||||||||||||
|
Subroutine
_handle_element_start: called CC=2 SCAR=6.9
| |||||||||||||||
| 90 | 76 | my($parser, $element_name, $attr_hash_r) = @_; | |||||||||||||
| 91 | # print "START $element_name\n"; | ||||||||||||||
| 92 | 76 | ▶ | if ($element_name =~m{^head\d$}xm) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 93 | # Test last section's content on every new section | ||||||||||||||
| 94 | 21 | $_test_content_sub->($parser, $_section, $_content); | |||||||||||||
| 95 | 17 | $_state = 'section'; | |||||||||||||
| 96 | 17 | $_content = q{}; | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | 72 | return; | |||||||||||||
| 99 | } | ||||||||||||||
| 100 | |||||||||||||||
| 101 | 68 | ▶ | sub _handle_element_end { | ||||||||||||
|
Subroutine
_handle_element_end: called CC=2 SCAR=7.6
| |||||||||||||||
| 102 | 68 | my($parser, $element_name) = @_; | |||||||||||||
| 103 | # print "END $element_name\n"; | ||||||||||||||
| 104 | 68 | ▶ | if ($element_name =~m{^Document$}xm) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 105 | 0 | $_test_content_sub->($parser, $_section, $_content); | |||||||||||||
| 106 | } | ||||||||||||||
| 107 | 68 | return; | |||||||||||||
| 108 | } | ||||||||||||||
| 109 | |||||||||||||||
| 110 | 68 | ▶ | sub _handle_text { | ||||||||||||
|
Subroutine
_handle_text: called CC=3 SCAR=11.0
| |||||||||||||||
| 111 | 68 | my($parser, $text) = @_; | |||||||||||||
| 112 | # print "TEXT $text\n"; | ||||||||||||||
| 113 | 68 | ▶ | if ($_state eq 'section') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 114 | 17 | $_section = $text; | |||||||||||||
| 115 | 17 | $_state = 'section_content_start'; | |||||||||||||
| 116 | 17 | return; | |||||||||||||
| 117 | } | ||||||||||||||
| 118 | 51 | ▶ | if ($_state eq 'section_content_start') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 119 | 51 | $_content .= $text; | |||||||||||||
| 120 | } | ||||||||||||||
| 121 | 51 | return; | |||||||||||||
| 122 | } | ||||||||||||||
| 123 | |||||||||||||||
| 124 | |||||||||||||||
| 125 | 2 | 1; | |||||||||||||
| 126 | |||||||||||||||
| 127 | __END__ | ||||||||||||||