blib/lib/Pod/Simple/Words.pm

filter: Statementstmt 92.5% 100 / 108 Branchbran 94.2% 49 / 52 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 88.8% 16 / 18 Podpod 100% 4 / 4 totaltotal 93.1% 177 / 190 CC 33 SCAR 21.1
CC
33
Cov
93%
_handle_text
15.2
_handle_element_start
11.0
_handle_element_end
6.0
CRAP 8.2
↑ Summary
1 package Pod::Simple::Words;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use experimental qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use JSON::MaybeXS qw( encode_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Text::HumanComputerWords 0.02;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use base qw( Pod::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # ABSTRACT: Parse words and locations from a POD document
14 1 our $VERSION = '0.07'; # VERSION
15  
16  
17 1 __PACKAGE__->_accessorize(
18 qw( line_number in_verbatim in_head1 callback target head1 skip_section_hash link_address in_section_title splitter ),
19 );
20  
21  
22 17 ▶sub new ($class)
Subroutine new: called CC=2 SCAR=7.0
Pod documented
23 {
24 17 my $self = $class->SUPER::new;
25 17 $self->preserve_whitespace(1);
26 17 $self->in_verbatim(0);
27 17 $self->in_head1(0);
28 17 $self->in_section_title(0);
29 17 $self->head1('');
30 17 $self->no_errata_section(1);
31 17 $self->accept_targets( qw( stopwords ));
32 17 $self->target(undef);
33 17 $self->skip_section_hash({});
34 17 ▶ if(! defined $self->splitter)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->splitter) 17 0 17
35 {
36 17 $self->splitter(
37 Text::HumanComputerWords->new(
38 Text::HumanComputerWords->default_perl,
39 ),
40 );
41 }
42 0 ▶ $self->callback(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 0 my $row = encode_json \@_;
44 0 print "--- $row\n";
45 17 });
46 17 $self;
47 }
48  
49  
50 1 ▶sub skip_sections ($self, @sections)
Subroutine skip_sections: called CC=2 SCAR=6.9
Pod documented
51 {
52 1 $self->skip_section_hash->{lc $_} = 1 for @sections;
53 }
54  
55 103 ▶sub _handle_element_start ($self, $tagname, $attrhash, @)
Subroutine _handle_element_start: called CC=11 SCAR=24.0
56 {
57 103 ▶ $self->line_number($attrhash->{start_line}) if defined $attrhash->{start_line};
Branch: 1 branch
BranchTrueFalseTotal
if defined $attrhash->{"start_line"} 94 9 103
58  
59 103 ▶ if($tagname eq 'L')
Branch: 5 branches
BranchTrueFalseTotal
if ($tagname eq 'L') { } 9 94 103
elsif ($tagname eq 'for') { } 2 92 94
elsif ($tagname eq 'Verbatim') { } 3 89 92
elsif ($tagname eq 'head1') { } 19 70 89
elsif ($tagname =~ /^head[0-9]+$/u) { } 3 67 70
60 {
61 9 my @row = ( $attrhash->{type} . "_link", $self->source_filename, $self->line_number, [undef, undef] );
62 9 ▶ if($attrhash->{type} eq 'url')
Branch: 1 branch
BranchTrueFalseTotal
if ($attrhash->{'type'} eq 'url') { } 3 6 9
63 {
64 3 my $url = URI->new($attrhash->{to});
65 3 ▶ if(defined $url->fragment)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url->fragment) 1 2 3
66 {
67 1 $row[3]->[1] = $url->fragment;
68 1 $url->fragment(undef);
69 }
70 3 $row[3]->[0] = "$url";
71 }
72 else
73 {
74 6 ▶ $row[3]->[0] = $attrhash->{to} . '' if defined $attrhash->{to};
Branch: 1 branch
BranchTrueFalseTotal
if defined $attrhash->{"to"} 5 1 6
75 6 ▶ $row[3]->[1] = $attrhash->{section} . '' if defined $attrhash->{section};
Branch: 1 branch
BranchTrueFalseTotal
if defined $attrhash->{"section"} 3 3 6
76 }
77 9 $self->callback->(@row);
78 9 $self->link_address($attrhash->{to});
79 }
80 elsif($tagname eq 'for')
81 {
82 2 $self->target($attrhash->{target});
83 }
84 elsif($tagname eq 'Verbatim')
85 {
86 3 $self->in_verbatim($self->in_verbatim+1);
87 }
88 elsif($tagname eq 'head1')
89 {
90 19 $self->in_head1($self->in_head1+1);
91 19 $self->head1('');
92 19 $self->in_section_title(1);
93 }
94 elsif($tagname =~ /^head[0-9]+$/)
95 {
96 3 $self->in_section_title(1);
97 }
98 103 ();
99 }
100  
101 103 ▶sub _handle_element_end ($self, $tagname, @)
Subroutine _handle_element_end: called CC=6 SCAR=17.9
102 {
103 103 ▶ if($tagname eq 'Verbatim')
Branch: 5 branches
BranchTrueFalseTotal
if ($tagname eq 'Verbatim') { } 3 100 103
elsif ($tagname eq 'head1') { } 19 81 100
elsif ($tagname =~ /^head[0-9]+$/u) { } 3 78 81
elsif ($tagname eq 'for') { } 2 76 78
elsif ($tagname eq 'L') { } 9 67 76
104 {
105 3 $self->in_verbatim($self->in_verbatim-1);
106 }
107 elsif($tagname eq 'head1')
108 {
109 19 $self->in_head1($self->in_head1-1);
110 19 $self->in_section_title(0);
111 }
112 elsif($tagname =~ /^head[0-9]+$/)
113 {
114 3 $self->in_section_title(0);
115 }
116 elsif($tagname eq 'for')
117 {
118 2 $self->target(undef);
119 }
120 elsif($tagname eq 'L')
121 {
122 9 $self->link_address(undef);
123 }
124 }
125  
126 63 ▶sub _add_words ($self, $line)
Subroutine _add_words: called CC=2 SCAR=6.9
127 {
128 63 foreach my $event ($self->splitter->split($line))
129 {
130 99 my($type, $word) = @$event;
131 99 my @row = ( $type, $self->source_filename, $self->line_number, $word );
132 99 $self->callback->(@row);
133 }
134 }
135  
136 1 ▶sub whine ($self, $line, $complaint)
Subroutine whine: called CC=1 SCAR=0.0
Pod documented
137 {
138 1 my @row = ( 'error', $self->source_filename, $self->line_number, $complaint );
139 1 $self->callback->(@row);
140 1 $self->SUPER::whine($line, $complaint);
141 }
142  
143 0 ▶sub scream ($self, $line, $complaint)
Subroutine scream: not called CC=1 SCAR=6.9
Pod documented
144 {
145 0 my @row = ( 'error', $self->source_filename, $self->line_number, $complaint );
146 0 $self->callback->(@row);
147 0 $self->SUPER::scream($line, $complaint);
148 }
149  
150 68 ▶sub _handle_text ($self, $text)
Subroutine _handle_text: called CC=15 SCAR=27.2
151 {
152 68 ▶ return if defined $self->link_address && $self->link_address eq $text;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->link_address and $self->link_address eq $text 2 66 68
Condition100%3/3
defined $self->link_address and $self->link_address eq $text
!ll&&!rl&&r
6062
MC/DC100%2/2
defined $self->link_address and $self->link_address eq $text
defined $self->link_address $self->link_address eq $text
Truth table100%3/3
A and B
A= defined $self->link_addressB= $self->link_address eq $text
ABresult
0X0
100
111
153  
154 66 ▶ if($self->in_section_title)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_section_title) 22 44 66
155 {
156 22 my @row = ( 'section', $self->source_filename, $self->line_number, $text );
157 22 $self->callback->(@row);
158 }
159  
160 66 ▶ if($self->in_head1)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_head1) { } 19 47 66
161 {
162 19 $self->head1(lc $text);
163 }
164 else
165 {
166 47 ▶ return if $self->skip_section_hash->{$self->head1};
Branch: 1 branch
BranchTrueFalseTotal
if $self->skip_section_hash->{$self->head1} 1 46 47
167 }
168 65 ▶ if($self->target)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->target) { } 2 63 65
elsif ($self->in_verbatim) { } 3 60 63
169 {
170 2 ▶ if($self->target eq 'stopwords')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->target eq "stopwords") 2 0 2
171 {
172 2 foreach my $word (split /\b{wb}/, $text)
173 {
174 10 ▶ next unless $word =~ /\w/;
Branch: 1 branch
BranchTrueFalseTotal
unless $word =~ /\w/u 4 6 10
175 6 my @row = ( 'stopword', $self->source_filename, $self->line_number, $word );
176 6 $self->callback->(@row);
177 }
178 }
179 }
180 elsif($self->in_verbatim)
181 {
182 3 my $base_line = $self->line_number;
183 3 my $doc = PPI::Document->new(\$text);
184 3 ▶ foreach my $comment (($doc->find('PPI::Token::Comment') || [])->@*)
Condition100%2/2
$doc->find('PPI::Token::Comment') || []
l!l
21
MC/DC100%1/1
$doc->find('PPI::Token::Comment') || []
$doc->find('PPI::Token::Comment')
Truth table100%2/2
A
A= $doc->find('PPI::Token::Comment')
Aresult
11
00
185 {
186 3 $self->line_number($base_line + $comment->location->[0] - 1);
187 3 $self->_add_words("$comment");
188 }
189 }
190 else
191 {
192 60 ▶ $text = lc $text if $self->in_head1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->in_head1 19 41 60
193 60 ▶ while($text =~ /^(.*?)\r?\n(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^(.*?)\r?\n(.*)$/u) 0 60 60
194 {
195 0 $text = $2;
196 0 $self->_add_words($1);
197 0 $self->line_number($self->line_number+1);
198 }
199 60 $self->_add_words($text);
200 }
201 65 ();
202 }
203  
204 1 1;
205  
206 __END__
↑ Summary