blib/lib/Test/Pod/Content.pm

filter: Statementstmt 95.2% 81 / 85 Branchbran 70.0% 21 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 100% 2 / 2 totaltotal 90.0% 118 / 131 CC 18 SCAR 11.8
CC
18
Cov
89%
_find_file
6.1
pod_section_is
4.1
pod_section_like
4.1
CRAP 3.2
↑ Summary
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
BranchTrueFalseTotal
if ($section_name eq $section) 1 1 2
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
BranchTrueFalseTotal
if ($@) 1 0 1
unless $@ =~ /^OK\n$/mx 0 1 1
45  
46 1 ▶ if (not $found) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 0 1 1
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
BranchTrueFalseTotal
if ($section_name eq $section) 3 16 19
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
BranchTrueFalseTotal
if ($@) 3 0 3
unless $@ =~ /^OK\n$/mx 0 3 3
68  
69 3 ▶ if (not $found) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 0 3 3
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
BranchTrueFalseTotal
if -e $name 0 4 4
78 4 for my $path (@INC) {
79 23 ▶ return "$path/$name" if -e "$path/$name";
Branch: 1 branch
BranchTrueFalseTotal
if -e "$path/$name" 2 21 23
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
BranchTrueFalseTotal
if -e "$path/$name" 2 3 5
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
BranchTrueFalseTotal
if ($element_name =~ /^head\d$/mx) 21 55 76
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
BranchTrueFalseTotal
if ($element_name =~ /^Document$/mx) 0 68 68
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
BranchTrueFalseTotal
if ($_state eq "section") 17 51 68
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
BranchTrueFalseTotal
if ($_state eq "section_content_start") 51 0 51
119 51 $_content .= $text;
120 }
121 51 return;
122 }
123  
124  
125 2 1;
126  
127 __END__
↑ Summary