Manipulator.pm

filter: Statementstmt 97.0% 462 / 476 Branchbran 83.8% 156 / 186 Conditioncond 72.6% 69 / 95 MC/DCmcdc 57.3% 35 / 61 Subroutinesub 100% 55 / 55 Podpod 0.0% 0 / 15 totaltotal 87.5% 777 / 888 CC 138 SCAR 19.1
CC
138
Cov
91%
extract_all
15.2
comment_handler
12.0
start_handler
12.0
CRAP 6.8
↑ Summary Manipulator/Document.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::Manipulator;
4  
5 2 our $VERSION = '0.07';
6  
7 9 ▶sub replace {
Subroutine replace: called CC=6 SCAR=18.4
Pod undocumented
8 9 my ( $html, %data ) = @_;
9  
10 # make comment "id" insensitive
11 9 my @keys = keys %data;
12 9 foreach (@keys) {
13 13 my $old = $_;
14 13 ▶ if (/^<!--/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^<!--/) 1 12 13
15 1 s/\s//g;
16 1 $_ = lc $_;
17 1 ▶ if ( $old ne $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old ne $_) 1 0 1
18 1 $data{$_} = delete $data{$old};
19 }
20 }
21 }
22 9 my $parser = new HTML::Manipulator::Replacer( \%data );
23 9 ▶ if ( UNIVERSAL::isa( $html, 'GLOB' ) or UNIVERSAL::isa( \$html, 'GLOB' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($html, 'GLOB') or UNIVERSAL::isa(\$html, 'GLOB')) { } 0 9 9
Condition33%1/3
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
l!l&&r!l&&!r
009
MC/DC0%0/2
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
UNIVERSAL::isa($html, "GLOB") UNIVERSAL::isa(\$html, "GLOB")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($html, "GLOB")B= UNIVERSAL::isa(\$html, "GLOB")
ABresult
1X1
011
000
24 0 $parser->parse_file($html);
25 } else {
26 9 $parser->parse($html);
27 9 $parser->eof;
28 }
29 9 return $parser->{_collect};
30 }
31  
32 4 ▶sub remove {
Subroutine remove: called CC=5 SCAR=16.6
Pod undocumented
33 4 my ( $html, @ids ) = @_;
34  
35 # make comment "id" insensitive
36 4 foreach (@ids) {
37 6 ▶ if (/^<!--/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^<!--/) 1 5 6
38 1 s/\s//g;
39 1 $_ = lc $_;
40 }
41 }
42 4 my $parser = new HTML::Manipulator::Remover(@ids);
43 4 ▶ if ( UNIVERSAL::isa( $html, 'GLOB' ) or UNIVERSAL::isa( \$html, 'GLOB' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($html, 'GLOB') or UNIVERSAL::isa(\$html, 'GLOB')) { } 0 4 4
Condition33%1/3
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
l!l&&r!l&&!r
004
MC/DC0%0/2
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
UNIVERSAL::isa($html, "GLOB") UNIVERSAL::isa(\$html, "GLOB")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($html, "GLOB")B= UNIVERSAL::isa(\$html, "GLOB")
ABresult
1X1
011
000
44 0 $parser->parse_file($html);
45 } else {
46 4 $parser->parse($html);
47 4 $parser->eof;
48 }
49  
50 4 return $parser->{_collect};
51 }
52  
53 21 ▶sub insert_adjacent {
Subroutine insert_adjacent: called CC=10 SCAR=23.9
Pod undocumented
54 21 my ( $html, %data ) = @_;
55  
56 # slurp (because this will be multi-pass
57 21 ▶ if ( UNIVERSAL::isa( $html, 'GLOB' ) or UNIVERSAL::isa( \$html, 'GLOB' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")) 0 21 21
Condition33%1/3
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
l!l&&r!l&&!r
0021
MC/DC0%0/2
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
UNIVERSAL::isa($html, "GLOB") UNIVERSAL::isa(\$html, "GLOB")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($html, "GLOB")B= UNIVERSAL::isa(\$html, "GLOB")
ABresult
1X1
011
000
58 0 $html = join '', <$html>;
59 }
60  
61 # make comment "id" insensitive
62 21 my %keys;
63 21 my @parts = values %data;
64 21 foreach (@parts) {
65 21 my $h = $_;
66 21 foreach ( keys %$h ) {
67 46 my $old = $_;
68 46 ▶ if (/^<!--/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^<!--/) 13 33 46
69 13 s/\s//g;
70 13 $_ = lc $_;
71 13 ▶ if ( $old ne $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old ne $_) 13 0 13
72 13 $h->{$_} = delete $h->{$old};
73 }
74 }
75 46 $keys{$_} = 1;
76 }
77 }
78  
79 21 my @keys = keys %keys;
80  
81 21 ▶ while (@keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) 30 21 51
82 30 my $parser = new HTML::Manipulator::Inserter( \%data );
83 30 $parser->parse($html);
84 30 $parser->eof;
85 30 $html = $parser->{_collect};
86 30 ▶ if ( ref $parser->{_found} and keys %{ $parser->{_found} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parser->{'_found'} and keys %{$$parser{'_found'};}) { } 30 0 30
Condition33%1/3
ref $parser->{"_found"} and keys %{$$parser{"_found"};}
!ll&&!rl&&r
0030
MC/DC0%0/2
ref $parser->{"_found"} and keys %{$$parser{"_found"};}
ref $parser->{"_found"} keys %{$$parser{"_found"};}
Truth table33%1/3
A and B
A= ref $parser->{"_found"}B= keys %{$$parser{"_found"};}
ABresult
0X0
100
111
87  
88 # retry with keys that have not been found
89 30 @keys = grep { not exists $parser->{_found}{$_} } @keys;
90  
91 } else {
92 0 @keys = ();
93 }
94  
95 }
96 21 return $html;
97 }
98  
99 5 ▶sub insert_before_begin {
Subroutine insert_before_begin: called CC=1 SCAR=0.0
Pod undocumented
100 5 my ( $html, %data ) = @_;
101 5 return insert_adjacent( $html, before_begin => \%data );
102 }
103  
104 5 ▶sub insert_after_end {
Subroutine insert_after_end: called CC=1 SCAR=0.0
Pod undocumented
105 5 my ( $html, %data ) = @_;
106 5 return insert_adjacent( $html, after_end => \%data );
107 }
108  
109 5 ▶sub insert_after_begin {
Subroutine insert_after_begin: called CC=1 SCAR=0.0
Pod undocumented
110 5 my ( $html, %data ) = @_;
111 5 return insert_adjacent( $html, after_begin => \%data );
112 }
113  
114 6 ▶sub insert_before_end {
Subroutine insert_before_end: called CC=1 SCAR=0.0
Pod undocumented
115 6 my ( $html, %data ) = @_;
116 6 return insert_adjacent( $html, before_end => \%data );
117 }
118  
119 2 ▶sub replace_title {
Subroutine replace_title: called CC=3 SCAR=12.0
Pod undocumented
120 2 my ( $html, $title ) = @_;
121 2 my $parser = new HTML::Manipulator::TitleReplacer($title);
122 2 ▶ if ( UNIVERSAL::isa( $html, 'GLOB' ) or UNIVERSAL::isa( \$html, 'GLOB' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($html, 'GLOB') or UNIVERSAL::isa(\$html, 'GLOB')) { } 0 2 2
Condition33%1/3
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
l!l&&r!l&&!r
002
MC/DC0%0/2
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
UNIVERSAL::isa($html, "GLOB") UNIVERSAL::isa(\$html, "GLOB")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($html, "GLOB")B= UNIVERSAL::isa(\$html, "GLOB")
ABresult
1X1
011
000
123 0 $parser->parse_file($html);
124 } else {
125 2 $parser->parse($html);
126 2 $parser->eof;
127 }
128 2 return $parser->{_collect};
129 }
130  
131 2 ▶sub extract {
Subroutine extract: called CC=2 SCAR=7.1
Pod undocumented
132 2 my ( $html, $id ) = @_;
133 2 my $result = extract_all( $html, $id );
134 2 ▶ return ref $result ? $result->{$id} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $result ? : 2 0 2
135 }
136  
137 3 ▶sub extract_content {
Subroutine extract_content: called CC=2 SCAR=7.1
Pod undocumented
138 3 my ( $html, $id ) = @_;
139 3 my $result = extract_all_content( $html, $id );
140 3 ▶ return ref $result ? $result->{$id} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $result ? : 3 0 3
141 }
142  
143 13 ▶sub extract_all {
Subroutine extract_all: called CC=15 SCAR=27.2
Pod undocumented
144 13 my ( $html, @ids ) = @_;
145 13 ▶ if ( UNIVERSAL::isa( $html, 'GLOB' ) or UNIVERSAL::isa( \$html, 'GLOB' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")) 1 12 13
Condition66%2/3
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
l!l&&r!l&&!r
0112
MC/DC50%1/2
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
UNIVERSAL::isa($html, "GLOB") UNIVERSAL::isa(\$html, "GLOB")
Truth table66%2/3
A or B
A= UNIVERSAL::isa($html, "GLOB")B= UNIVERSAL::isa(\$html, "GLOB")
ABresult
1X1
011
000
146 1 $html = join '', <$html>;
147 }
148 13 my %comment_id_map;
149 13 ▶ if (@ids) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ids) { } 7 6 13
150 7 foreach (@ids) {
151 10 my $old = $_;
152 10 ▶ if ( not ref $_ and $_ =~ /^<!--/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_ and $_ =~ /^<!--/) 2 8 10
Condition100%3/3
not ref $_ and $_ =~ /^<!--/
!ll&&!rl&&r
262
MC/DC100%2/2
not ref $_ and $_ =~ /^<!--/
not ref $_ $_ =~ /^<!--/
Truth table100%3/3
not(A) and B
A= not ref $_B= $_ =~ /^<!--/
ABresult
0X0
100
111
153 2 s/\s//g;
154 2 $_ = lc $_;
155 2 ▶ $comment_id_map{$_} = $old if $old ne $_;
Branch: 1 branch
BranchTrueFalseTotal
if $old ne $_ 2 0 2
156 }
157 }
158 7 foreach (@ids) {
159 9 ▶ if ( ref $_ eq 'Regexp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq "Regexp") 1 8 9
160 @ids =
161 1 keys %{ extract_all_ids( $html, @ids ) };
162 1 last;
163 }
164 }
165 } else {
166 6 @ids = keys %{ extract_all_ids($html) };
167 }
168 13 ▶ return {} unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 1 12 13
169  
170 12 my %result;
171 12 ▶ while (@ids) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ids) 25 12 37
172 25 my $parser = new HTML::Manipulator::Extractor(@ids);
173  
174 25 $parser->parse($html);
175 25 $parser->eof;
176 25 ▶ if ( ref $parser->{_found} and keys %{ $parser->{_found} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parser->{'_found'} and keys %{$$parser{'_found'};}) { } 25 0 25
Condition33%1/3
ref $parser->{"_found"} and keys %{$$parser{"_found"};}
!ll&&!rl&&r
0025
MC/DC0%0/2
ref $parser->{"_found"} and keys %{$$parser{"_found"};}
ref $parser->{"_found"} keys %{$$parser{"_found"};}
Truth table33%1/3
A and B
A= ref $parser->{"_found"}B= keys %{$$parser{"_found"};}
ABresult
0X0
100
111
177 25 %result = ( %result, %{ $parser->{_found} } );
178 25 @ids = grep { not exists $result{$_} } @ids;
179 } else {
180 0 @ids = ();
181 }
182 }
183  
184 # fix comment ids
185 12 foreach ( keys %comment_id_map ) {
186 2 $result{ $comment_id_map{$_} } = $result{$_};
187 2 delete $result{$_};
188 }
189 12 return \%result;
190 }
191  
192 10 ▶sub extract_all_content {
Subroutine extract_all_content: called CC=2 SCAR=7.0
Pod undocumented
193 10 my ( $html, @ids ) = @_;
194 10 my $result = extract_all( $html, @ids );
195 10 ▶ return {} unless ref $result;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $result 0 10 10
196 2 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
197  
198 # warn Dumper $result;
199 10 return { map { ( $_ => $result->{$_}{_content} ) } keys %$result };
200 }
201  
202 10 ▶sub extract_all_ids {
Subroutine extract_all_ids: called CC=4 SCAR=14.8
Pod undocumented
203 10 my ( $html, @filter ) = @_;
204 10 my $parser = new HTML::Manipulator::IDExtractor(@filter);
205 10 ▶ if ( UNIVERSAL::isa( $html, 'GLOB' ) or UNIVERSAL::isa( \$html, 'GLOB' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($html, 'GLOB') or UNIVERSAL::isa(\$html, 'GLOB')) { } 0 10 10
Condition33%1/3
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
l!l&&r!l&&!r
0010
MC/DC0%0/2
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
UNIVERSAL::isa($html, "GLOB") UNIVERSAL::isa(\$html, "GLOB")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($html, "GLOB")B= UNIVERSAL::isa(\$html, "GLOB")
ABresult
1X1
011
000
206 0 $parser->parse_file($html);
207 } else {
208 10 $parser->parse($html);
209 10 $parser->eof;
210 }
211 10 ▶ return $parser->{_found} || {};
Condition100%2/2
$parser->{'_found'} || {}
l!l
91
MC/DC100%1/1
$parser->{'_found'} || {}
$parser->{'_found'}
Truth table100%2/2
A
A= $parser->{'_found'}
Aresult
11
00
212 }
213  
214 2 ▶sub extract_title {
Subroutine extract_title: called CC=3 SCAR=12.0
Pod undocumented
215 2 my ($html) = @_;
216 2 my $parser = new HTML::Manipulator::TitleExtractor();
217 2 ▶ if ( UNIVERSAL::isa( $html, 'GLOB' ) or UNIVERSAL::isa( \$html, 'GLOB' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($html, 'GLOB') or UNIVERSAL::isa(\$html, 'GLOB')) { } 0 2 2
Condition33%1/3
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
l!l&&r!l&&!r
002
MC/DC0%0/2
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
UNIVERSAL::isa($html, "GLOB") UNIVERSAL::isa(\$html, "GLOB")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($html, "GLOB")B= UNIVERSAL::isa(\$html, "GLOB")
ABresult
1X1
011
000
218 0 $parser->parse_file($html);
219 } else {
220 2 $parser->parse($html);
221 2 $parser->eof;
222 }
223 2 return $parser->{_found};
224 }
225  
226 3 ▶sub extract_all_comments {
Subroutine extract_all_comments: called CC=3 SCAR=11.7
Pod undocumented
227 3 my ( $html, @filter ) = @_;
228 3 my @result;
229 3 my $parser = new HTML::Manipulator::CommentExtractor(@filter);
230 3 ▶ if ( UNIVERSAL::isa( $html, 'GLOB' ) or UNIVERSAL::isa( \$html, 'GLOB' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($html, 'GLOB') or UNIVERSAL::isa(\$html, 'GLOB')) { } 0 3 3
Condition33%1/3
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
l!l&&r!l&&!r
003
MC/DC0%0/2
UNIVERSAL::isa($html, "GLOB") or UNIVERSAL::isa(\$html, "GLOB")
UNIVERSAL::isa($html, "GLOB") UNIVERSAL::isa(\$html, "GLOB")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($html, "GLOB")B= UNIVERSAL::isa(\$html, "GLOB")
ABresult
1X1
011
000
231 0 $parser->parse_file($html);
232 } else {
233 3 $parser->parse($html);
234 3 $parser->eof;
235 }
236 3 return @{ $parser->{_found} };
237 }
238  
239 package HTML::Manipulator::Replacer;
240 2 ▶use base qw(HTML::Parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
241  
242 51 ▶sub start_handler {
Subroutine start_handler: called CC=12 SCAR=24.9
243 51 my ( $self, $type, $attr, $text, $skip ) = @_;
244 51 my $id = $attr->{id};
245 51 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_watch_for"}) 22 29 51
246 22 ▶ $self->{_watch_for_depth}++ if $self->{_watch_for} eq $type;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_watch_for"} eq $type 3 19 22
247 22 return;
248 }
249 29 $self->{_collect} .= $skip;
250 29 ▶ unless ( $id and exists $self->{_update_ids}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id and exists $self->{"_update_ids"}{$id}) 20 9 29
Condition100%3/3
$id and exists $self->{"_update_ids"}{$id}
!ll&&!rl&&r
1829
MC/DC100%2/2
$id and exists $self->{"_update_ids"}{$id}
$id exists $self->{"_update_ids"}{$id}
Truth table100%3/3
A and B
A= $idB= exists $self->{"_update_ids"}{$id}
ABresult
0X0
100
111
251 20 $self->{_collect} .= $text;
252 20 return;
253 }
254 9 my $content = $self->{_update_ids}{$id};
255 9 my %new_values;
256 9 ▶ if ( ref $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content) 2 7 9
257 2 %new_values = %$content;
258 2 foreach ( keys %new_values ) {
259 4 ▶ if ( $_ ne lc $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ ne lc $_) 1 3 4
260 1 $new_values{ lc $_ } = delete $new_values{$_};
261 }
262 }
263  
264 2 $content = delete $new_values{'_content'};
265 }
266  
267 9 ▶ if (%new_values) {
Branch: 1 branch
BranchTrueFalseTotal
if (%new_values) { } 2 7 9
268 2 my %attr = ( %$attr, %new_values );
269 2 $self->{_collect} .= "<$type";
270 2 foreach ( sort keys %attr ) {
271 4 ▶ if ( index( $attr{$_}, "'" ) == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($attr{$_}, q[']) == -1) { } 3 1 4
272 3 $self->{_collect} .= qq[ $_='$attr{$_}'];
273 } else {
274 1 $self->{_collect} .= qq[ $_="$attr{$_}"];
275 }
276 }
277 2 $self->{_collect} .= ">";
278 } else {
279 7 $self->{_collect} .= $text;
280 }
281 9 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) 9 0 9
282 9 $self->{_watch_for} = $type;
283 9 $self->{_collect} .= $content;
284 }
285 }
286  
287 43 ▶sub end_handler {
Subroutine end_handler: called CC=4 SCAR=13.9
288 43 my ( $self, $type, $text, $skip ) = @_;
289 43 ▶ unless ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_watch_for"}) 18 25 43
290 18 $self->{_collect} .= $skip;
291 18 $self->{_collect} .= $text;
292 18 return;
293 }
294 25 ▶ if ( $type eq $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $self->{"_watch_for"}) 12 13 25
295 12 $self->{_watch_for_depth}--;
296 12 ▶ if ( $self->{_watch_for_depth} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_watch_for_depth"}) 9 3 12
297 9 $self->{_collect} .= $text;
298 9 delete $self->{_watch_for};
299 }
300 }
301 }
302  
303 9 ▶sub end_document_handler {
Subroutine end_document_handler: called CC=1 SCAR=0.0
304 9 my ( $self, $text ) = @_;
305 9 $self->{_collect} .= $text;
306 }
307  
308 4 ▶sub comment_handler {
Subroutine comment_handler: called CC=5 SCAR=16.1
309 4 my ( $self, $text, $skip ) = @_;
310 4 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_watch_for"}) 2 2 4
311 2 ▶ if ( $self->{_watch_for} eq '<!--' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_watch_for"} eq "<!--") 1 1 2
312 1 delete $self->{_watch_for};
313 1 $self->{_collect} .= $text;
314 }
315 2 return;
316 }
317  
318 2 my $id = lc $text;
319 2 $id =~ s/\s//g;
320  
321 2 $self->{_collect} .= $skip;
322 2 $self->{_collect} .= $text;
323 2 ▶ unless ( $id and exists $self->{_update_ids}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id and exists $self->{"_update_ids"}{$id}) 1 1 2
Condition66%2/3
$id and exists $self->{"_update_ids"}{$id}
!ll&&!rl&&r
011
MC/DC50%1/2
$id and exists $self->{"_update_ids"}{$id}
$id exists $self->{"_update_ids"}{$id}
Truth table66%2/3
A and B
A= $idB= exists $self->{"_update_ids"}{$id}
ABresult
0X0
100
111
324 1 return;
325 }
326 1 $self->{_collect} .= $self->{_update_ids}{$id};
327 1 $self->{_watch_for} = '<!--';
328 }
329  
330 9 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
331 9 my ( $class, $args ) = @_;
332 9 my $self = HTML::Parser::new(
333 $class,
334 start_h =>
335 [ 'start_handler', "self,tagname, attr, text, skipped_text" ],
336 end_h => [ 'end_handler', "self,tagname, text, skipped_text" ],
337 end_document_h => [ 'end_document_handler', "self, skipped_text" ],
338 comment_h => [ 'comment_handler', 'self, text, skipped_text' ],
339 );
340  
341 9 $self->{_update_ids} = $args;
342 9 $self->{_collect} = '';
343 9 return $self;
344 }
345  
346 package HTML::Manipulator::Extractor;
347 2 ▶use base qw(HTML::Parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
348  
349 147 ▶sub start_handler {
Subroutine start_handler: called CC=5 SCAR=16.1
350 147 my ( $self, $type, $attr, $text, $skip ) = @_;
351 147 my $id = $attr->{id};
352 147 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_watch_for"}) 42 105 147
353 42 $self->{_found}{ $self->{_watch_for_id} }{_content} .= $skip . $text;
354 42 ▶ $self->{_watch_for_depth}++ if $self->{_watch_for} eq $type;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_watch_for"} eq $type 6 36 42
355 42 return;
356 }
357  
358 105 ▶ unless ( $id and exists $self->{_extract_ids}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id and exists $self->{"_extract_ids"}{$id}) 82 23 105
Condition100%3/3
$id and exists $self->{"_extract_ids"}{$id}
!ll&&!rl&&r
582423
MC/DC100%2/2
$id and exists $self->{"_extract_ids"}{$id}
$id exists $self->{"_extract_ids"}{$id}
Truth table100%3/3
A and B
A= $idB= exists $self->{"_extract_ids"}{$id}
ABresult
0X0
100
111
359 82 return;
360 }
361 23 $self->{_found}{$id} = $attr;
362 23 $self->{_found}{$id}{_start_tag} = $text;
363 23 $self->{_watch_for_id} = $id;
364 23 $self->{_watch_for} = $type;
365 }
366  
367 128 ▶sub end_handler {
Subroutine end_handler: called CC=5 SCAR=16.1
368 128 my ( $self, $type, $text, $skip ) = @_;
369 128 ▶ unless ( exists $self->{_watch_for} and $type eq $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_watch_for"} and $type eq $self->{"_watch_for"}) 99 29 128
Condition100%3/3
exists $self->{"_watch_for"} and $type eq $self->{"_watch_for"}
!ll&&!rl&&r
742529
MC/DC100%2/2
exists $self->{"_watch_for"} and $type eq $self->{"_watch_for"}
exists $self->{"_watch_for"} $type eq $self->{"_watch_for"}
Truth table100%3/3
A and B
A= exists $self->{"_watch_for"}B= $type eq $self->{"_watch_for"}
ABresult
0X0
100
111
370 99 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_watch_for"}) 25 74 99
371 $self->{_found}{ $self->{_watch_for_id} }{_content} .=
372 25 $skip . $text;
373 }
374 99 return;
375 }
376 29 $self->{_found}{ $self->{_watch_for_id} }{_content} .= $skip;
377  
378 29 $self->{_watch_for_depth}--;
379 29 ▶ if ( $self->{_watch_for_depth} >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_watch_for_depth"} >= 0) 6 23 29
380 6 $self->{_found}{ $self->{_watch_for_id} }{_content} .= $text;
381 6 return;
382 }
383 23 $self->{_found}{ $self->{_watch_for_id} }{_end_tag} = $text;
384 23 delete $self->{_watch_for};
385 }
386  
387 16 ▶sub comment_handler {
Subroutine comment_handler: called CC=4 SCAR=13.9
388 16 my ( $self, $text, $skip ) = @_;
389  
390 16 my $id = lc $text;
391 16 $id =~ s/\s//g;
392  
393 #warn "comment [$id] \n";
394  
395 16 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_watch_for"}) 5 11 16
396 5 ▶ if ( $self->{_watch_for_id} =~ /^<!--/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_watch_for_id"} =~ /^<!--/) 2 3 5
397 2 $self->{_found}{ $self->{_watch_for_id} }{_content} .= $skip;
398 2 $self->{_found}{ $self->{_watch_for_id} }{_end_tag} = $text;
399 2 delete $self->{_watch_for};
400 2 return;
401 }
402 3 $self->{_found}{ $self->{_watch_for_id} }{_content} .= $skip . $text;
403 3 return;
404 }
405  
406 11 ▶ unless ( exists $self->{_extract_ids}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_extract_ids"}{$id}) 9 2 11
407 9 return;
408 }
409 2 $self->{_found}{$id} = {};
410 2 $self->{_found}{$id}{_start_tag} = $text;
411 2 $self->{_watch_for_id} = $id;
412 2 $self->{_watch_for} = $id;
413  
414 #warn "watching for $id";
415 }
416  
417 25 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
418 25 my ( $class, @args ) = @_;
419 25 my $self = HTML::Parser::new(
420 $class,
421 start_h =>
422 [ 'start_handler', "self,tagname, attr, text, skipped_text" ],
423 end_h => [ 'end_handler', "self,tagname, text, skipped_text" ],
424 comment_h => [ 'comment_handler', 'self, text, skipped_text' ],
425 );
426  
427 25 my %args = map { ( $_ => 1 ) } @args;
428 25 $self->{_extract_ids} = \%args;
429  
430 25 return $self;
431 }
432  
433 package HTML::Manipulator::IDExtractor;
434 2 ▶use base qw(HTML::Parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
435  
436 63 ▶sub start_handler {
Subroutine start_handler: called CC=8 SCAR=20.8
437 63 my ( $self, $type, $attr ) = @_;
438 63 my $id = $attr->{id};
439 63 ▶ return unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 36 27 63
440 27 ▶ if ( $self->{_filter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_filter'}) { } 6 21 27
441 6 foreach ( @{ $self->{_filter} } ) {
442 12 ▶ if ( ref $_ eq 'Regexp' && $id =~ $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq "Regexp" and $id =~ /$_/i) 3 9 12
Condition100%3/3
ref $_ eq "Regexp" and $id =~ /$_/i
!ll&&!rl&&r
273
MC/DC100%2/2
ref $_ eq "Regexp" and $id =~ /$_/i
ref $_ eq "Regexp" $id =~ /$_/i
Truth table100%3/3
A and B
A= ref $_ eq "Regexp"B= $id =~ /$_/i
ABresult
0X0
100
111
443 3 $self->{_found}{$id} = $type;
444 3 return;
445 }
446 9 ▶ if ( not ref $_ and $_ eq $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_ and $_ eq $id) 1 8 9
Condition100%3/3
not ref $_ and $_ eq $id
!ll&&!rl&&r
711
MC/DC100%2/2
not ref $_ and $_ eq $id
not ref $_ $_ eq $id
Truth table100%3/3
not(A) and B
A= not ref $_B= $_ eq $id
ABresult
0X0
100
111
447 1 $self->{_found}{$id} = $type;
448 1 return;
449 }
450 }
451 } else {
452 21 $self->{_found}{$id} = $type;
453 }
454 }
455  
456 10 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
457 10 my ( $class, @args ) = @_;
458 10 my $self =
459 HTML::Parser::new( $class,
460 start_h => [ 'start_handler', "self, tagname, attr" ], );
461 10 ▶ $self->{_filter} = [@args] if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 2 8 10
462 10 return $self;
463 }
464  
465 package HTML::Manipulator::TitleExtractor;
466 2 ▶use base qw(HTML::Parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
467  
468 2 ▶sub start_handler {
Subroutine start_handler: called CC=3 SCAR=12.7
469 2 my ( $self, $type, $text, $skip ) = @_;
470 2 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_watch_for"}) 0 2 2
471 0 $self->{_found} .= $skip . $text;
472 0 return;
473 }
474 2 ▶ if ( $type eq 'title' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "title") 2 0 2
475 2 $self->{_watch_for} = 1;
476 }
477 }
478  
479 2 ▶sub end_handler {
Subroutine end_handler: called CC=3 SCAR=11.8
480 2 my ( $self, $type, $text, $skip ) = @_;
481 2 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_watch_for"}) 2 0 2
482 2 $self->{_found} .= $skip;
483 2 ▶ if ( $type eq 'title' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'title') { } 2 0 2
484 2 delete $self->{_watch_for};
485 } else {
486 0 $self->{_found} .= $text;
487 }
488 }
489 }
490  
491 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
492 2 my ( $class, @args ) = @_;
493 2 my $self = HTML::Parser::new(
494 $class,
495 start_h => [ 'start_handler', "self,tagname, text, skipped_text" ],
496 end_h => [ 'end_handler', "self,tagname, text, skipped_text" ],
497 );
498  
499 2 return $self;
500 }
501  
502 package HTML::Manipulator::TitleReplacer;
503 2 ▶use base qw(HTML::Parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
504  
505 2 ▶sub start_handler {
Subroutine start_handler: called CC=3 SCAR=11.3
506 2 my ( $self, $type, $text, $skip ) = @_;
507 2 ▶ unless ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_watch_for"}) 2 0 2
508 2 $self->{_collect} .= $skip . $text;
509 2 ▶ if ( $type eq 'title' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "title") 2 0 2
510 2 $self->{_watch_for} = 1;
511 }
512 }
513 }
514  
515 2 ▶sub end_handler {
Subroutine end_handler: called CC=3 SCAR=12.0
516 2 my ( $self, $type, $text, $skip ) = @_;
517 2 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_watch_for'}) { } 2 0 2
518 2 ▶ if ( $type eq 'title' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'title') { } 2 0 2
519 2 delete $self->{_watch_for};
520 2 $self->{_collect} .= $self->{_new_title};
521 } else {
522 0 $self->{_collect} .= $skip;
523 }
524 2 $self->{_collect} .= $text;
525 } else {
526 0 $self->{_collect} .= $skip . $text;
527 }
528 }
529  
530 2 ▶sub end_document_handler {
Subroutine end_document_handler: called CC=1 SCAR=0.0
531 2 my ( $self, $text ) = @_;
532 2 $self->{_collect} .= $text;
533 }
534  
535 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
536 2 my ( $class, $title ) = @_;
537 2 my $self = HTML::Parser::new(
538 $class,
539 start_h => [ 'start_handler', "self,tagname, text, skipped_text" ],
540 end_h => [ 'end_handler', "self,tagname, text, skipped_text" ],
541 end_document_h => [ 'end_document_handler', "self, skipped_text" ],
542 );
543 2 $self->{_new_title} = $title;
544 2 return $self;
545 }
546  
547 package HTML::Manipulator::CommentExtractor;
548 2 ▶use base qw(HTML::Parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
549  
550 9 ▶sub comment_handler {
Subroutine comment_handler: called CC=7 SCAR=19.5
551 9 my ( $self, $text, $token0 ) = @_;
552 9 ▶ if ( $self->{_filter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_filter'}) { } 3 6 9
553 3 my $id = lc $token0;
554 3 $id =~ s/\s//g;
555 3 foreach ( @{ $self->{_filter} } ) {
556 5 ▶ if ( ref $_ eq 'Regexp' && $id =~ $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq "Regexp" and $id =~ /$_/i) 1 4 5
Condition100%3/3
ref $_ eq "Regexp" and $id =~ /$_/i
!ll&&!rl&&r
311
MC/DC100%2/2
ref $_ eq "Regexp" and $id =~ /$_/i
ref $_ eq "Regexp" $id =~ /$_/i
Truth table100%3/3
A and B
A= ref $_ eq "Regexp"B= $id =~ /$_/i
ABresult
0X0
100
111
557 1 push @{ $self->{_found} }, $text;
558 1 return;
559 }
560 4 ▶ if ( not ref $_ and $_ eq $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_ and $_ eq $id) 1 3 4
Condition100%3/3
not ref $_ and $_ eq $id
!ll&&!rl&&r
121
MC/DC100%2/2
not ref $_ and $_ eq $id
not ref $_ $_ eq $id
Truth table100%3/3
not(A) and B
A= not ref $_B= $_ eq $id
ABresult
0X0
100
111
561 1 push @{ $self->{_found} }, $text;
562 1 return;
563 }
564 }
565 } else {
566 6 push @{ $self->{_found} }, $text;
567 6 return;
568 }
569 }
570  
571 3 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
572 3 my ( $class, @args ) = @_;
573 3 my $self =
574 HTML::Parser::new( $class,
575 comment_h => [ 'comment_handler', "self,text,token0" ], );
576 $self->{_filter} = [
577 map {
578 3 ▶ unless (ref) { $_ = lc $_; s/\s//g; }
Branch: 2 branches
BranchTrueFalseTotal
if @args 1 2 3
unless (ref $_) 1 1 2
579 2 $_;
580 } @args
581 ]
582 if @args;
583 3 return $self;
584 }
585  
586 package HTML::Manipulator::Remover;
587 2 ▶use base qw(HTML::Parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
588  
589 21 ▶sub start_handler {
Subroutine start_handler: called CC=5 SCAR=16.1
590 21 my ( $self, $type, $attr, $text, $skip ) = @_;
591 21 my $id = $attr->{id};
592 21 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_watch_for"}) 10 11 21
593 10 ▶ $self->{_watch_for_depth}++ if $self->{_watch_for} eq $type;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_watch_for"} eq $type 0 10 10
594 10 return;
595 }
596 11 $self->{_collect} .= $skip;
597 11 ▶ unless ( $id and exists $self->{_remove_ids}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id and exists $self->{"_remove_ids"}{$id}) 7 4 11
Condition100%3/3
$id and exists $self->{"_remove_ids"}{$id}
!ll&&!rl&&r
614
MC/DC100%2/2
$id and exists $self->{"_remove_ids"}{$id}
$id exists $self->{"_remove_ids"}{$id}
Truth table100%3/3
A and B
A= $idB= exists $self->{"_remove_ids"}{$id}
ABresult
0X0
100
111
598 7 $self->{_collect} .= $text;
599 7 return;
600 }
601  
602 4 $self->{_watch_for} = $type;
603  
604 }
605  
606 18 ▶sub end_handler {
Subroutine end_handler: called CC=4 SCAR=13.9
607 18 my ( $self, $type, $text, $skip ) = @_;
608 18 ▶ unless ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_watch_for"}) 7 11 18
609 7 $self->{_collect} .= $skip;
610 7 $self->{_collect} .= $text;
611 7 return;
612 }
613 11 ▶ if ( $type eq $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $self->{"_watch_for"}) 4 7 11
614 4 $self->{_watch_for_depth}--;
615 4 ▶ if ( $self->{_watch_for_depth} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_watch_for_depth"}) 4 0 4
616 4 delete $self->{_watch_for};
617 }
618 }
619 }
620  
621 4 ▶sub end_document_handler {
Subroutine end_document_handler: called CC=1 SCAR=0.0
622 4 my ( $self, $text ) = @_;
623 4 $self->{_collect} .= $text;
624 }
625  
626 3 ▶sub comment_handler {
Subroutine comment_handler: called CC=5 SCAR=16.1
627 3 my ( $self, $text, $skip ) = @_;
628 3 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_watch_for"}) 1 2 3
629 1 ▶ if ( $self->{_watch_for} eq '<!--' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_watch_for"} eq "<!--") 1 0 1
630 1 delete $self->{_watch_for};
631 }
632 1 return;
633 }
634  
635 2 my $id = lc $text;
636 2 $id =~ s/\s//g;
637  
638 2 $self->{_collect} .= $skip;
639 2 ▶ unless ( $id and exists $self->{_remove_ids}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id and exists $self->{"_remove_ids"}{$id}) 1 1 2
Condition66%2/3
$id and exists $self->{"_remove_ids"}{$id}
!ll&&!rl&&r
011
MC/DC50%1/2
$id and exists $self->{"_remove_ids"}{$id}
$id exists $self->{"_remove_ids"}{$id}
Truth table66%2/3
A and B
A= $idB= exists $self->{"_remove_ids"}{$id}
ABresult
0X0
100
111
640 1 $self->{_collect} .= $text;
641 1 return;
642 }
643 1 $self->{_watch_for} = '<!--';
644 }
645  
646 4 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
647 4 my ( $class, @args ) = @_;
648 4 my $self = HTML::Parser::new(
649 $class,
650 start_h =>
651 [ 'start_handler', "self,tagname, attr, text, skipped_text" ],
652 end_h => [ 'end_handler', "self,tagname, text, skipped_text" ],
653 end_document_h => [ 'end_document_handler', "self, skipped_text" ],
654 comment_h => [ 'comment_handler', 'self, text, skipped_text' ],
655 );
656  
657 4 foreach (@args) {
658 6 $self->{_remove_ids}{$_} = 1;
659 }
660 4 $self->{_collect} = '';
661 4 return $self;
662 }
663  
664 package HTML::Manipulator::Inserter;
665 2 ▶use base qw(HTML::Parser);
Subroutine BEGIN: called CC=1 SCAR=0.0
666  
667 130 ▶sub start_handler {
Subroutine start_handler: called CC=10 SCAR=23.0
668 130 my ( $self, $type, $attr, $text, $skip ) = @_;
669 130 my $id = $attr->{id};
670 130 $self->{_collect} .= $skip;
671 130 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_watch_for"}) 30 100 130
672 30 $self->{_collect} .= $text;
673 30 ▶ $self->{_watch_for_depth}++ if $self->{_watch_for} eq $type;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_watch_for"} eq $type 0 30 30
674  
675 30 return;
676 }
677  
678 100 ▶ if ( $id and exists $self->{_insert_ids_beforeBegin}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id and exists $self->{"_insert_ids_beforeBegin"}{$id}) 8 92 100
Condition100%3/3
$id and exists $self->{"_insert_ids_beforeBegin"}{$id}
!ll&&!rl&&r
42508
MC/DC100%2/2
$id and exists $self->{"_insert_ids_beforeBegin"}{$id}
$id exists $self->{"_insert_ids_beforeBegin"}{$id}
Truth table100%3/3
A and B
A= $idB= exists $self->{"_insert_ids_beforeBegin"}{$id}
ABresult
0X0
100
111
679 8 $self->{_collect} .= $self->{_insert_ids_beforeBegin}{$id};
680 8 delete $self->{_insert_ids_beforeBegin}{$id};
681 8 $self->{_found}{$id} = 1;
682 }
683  
684 100 $self->{_collect} .= $text;
685  
686 100 ▶ if ( $id and exists $self->{_insert_ids_afterBegin}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id and exists $self->{"_insert_ids_afterBegin"}{$id}) 8 92 100
Condition100%3/3
$id and exists $self->{"_insert_ids_afterBegin"}{$id}
!ll&&!rl&&r
42508
MC/DC100%2/2
$id and exists $self->{"_insert_ids_afterBegin"}{$id}
$id exists $self->{"_insert_ids_afterBegin"}{$id}
Truth table100%3/3
A and B
A= $idB= exists $self->{"_insert_ids_afterBegin"}{$id}
ABresult
0X0
100
111
687 8 $self->{_collect} .= $self->{_insert_ids_afterBegin}{$id};
688 8 delete $self->{_insert_ids_afterBegin}{$id};
689 8 $self->{_found}{$id} = 1;
690 }
691  
692 100 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($id and exists $self->{"_insert_ids_afterEnd"}{$id} || exists $self->{"_insert_ids_beforeEnd"}{$id}) 83 17 100
Condition100%6/6
$id and exists $self->{"_insert_ids_afterEnd"}{$id} || exists $self->{"_insert_ids_beforeEnd"}{$id}
!ll&&!rl&&r
424117
exists $self->{"_insert_ids_afterEnd"}{$id} or exists $self->{"_insert_ids_beforeEnd"}{$id}
l!l&&r!l&&!r
8941
MC/DC100%3/3
$id and exists $self->{"_insert_ids_afterEnd"}{$id} || exists $self->{"_insert_ids_beforeEnd"}{$id}
$id exists $self->{"_insert_ids_afterEnd"}{$id} exists $self->{"_insert_ids_beforeEnd"}{$id}
Truth table100%4/4
A and B or C
A= $idB= exists $self->{"_insert_ids_afterEnd"}{$id}C= exists $self->{"_insert_ids_beforeEnd"}{$id}
ABCresult
0XX0
1000
11X1
1011
693 $id
694 and ( exists $self->{_insert_ids_afterEnd}{$id}
695 or exists $self->{_insert_ids_beforeEnd}{$id} )
696 )
697 {
698 83 return;
699 }
700 17 $self->{_watch_for} = $type;
701 17 $self->{_watch_for_id} = $id;
702  
703 }
704  
705 118 ▶sub end_handler {
Subroutine end_handler: called CC=9 SCAR=22.1
706 118 my ( $self, $type, $text, $skip ) = @_;
707 118 $self->{_collect} .= $skip;
708  
709 118 ▶ unless ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_watch_for"}) 75 43 118
710 75 $self->{_collect} .= $text;
711 75 return;
712 }
713  
714 43 ▶ if ( $type eq $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $self->{'_watch_for'}) { } 17 26 43
715 17 $self->{_watch_for_depth}--;
716  
717 17 ▶ if ( $self->{_watch_for_depth} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_watch_for_depth"}) 17 0 17
718 17 my $id = $self->{_watch_for_id};
719 17 ▶ if ( $id and exists $self->{_insert_ids_beforeEnd}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id and exists $self->{"_insert_ids_beforeEnd"}{$id}) 9 8 17
Condition66%2/3
$id and exists $self->{"_insert_ids_beforeEnd"}{$id}
!ll&&!rl&&r
089
MC/DC50%1/2
$id and exists $self->{"_insert_ids_beforeEnd"}{$id}
$id exists $self->{"_insert_ids_beforeEnd"}{$id}
Truth table66%2/3
A and B
A= $idB= exists $self->{"_insert_ids_beforeEnd"}{$id}
ABresult
0X0
100
111
720 9 $self->{_collect} .= $self->{_insert_ids_beforeEnd}{$id};
721 9 delete $self->{_insert_ids_beforeEnd}{$id};
722 9 $self->{_found}{$id} = 1;
723 }
724 17 delete $self->{_watch_for};
725 }
726  
727 17 $self->{_collect} .= $text;
728  
729 17 ▶ if ( $self->{_watch_for_depth} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_watch_for_depth"}) 17 0 17
730 17 my $id = $self->{_watch_for_id};
731 17 ▶ if ( $id and exists $self->{_insert_ids_afterEnd}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id and exists $self->{"_insert_ids_afterEnd"}{$id}) 8 9 17
Condition66%2/3
$id and exists $self->{"_insert_ids_afterEnd"}{$id}
!ll&&!rl&&r
098
MC/DC50%1/2
$id and exists $self->{"_insert_ids_afterEnd"}{$id}
$id exists $self->{"_insert_ids_afterEnd"}{$id}
Truth table66%2/3
A and B
A= $idB= exists $self->{"_insert_ids_afterEnd"}{$id}
ABresult
0X0
100
111
732 8 $self->{_collect} .= $self->{_insert_ids_afterEnd}{$id};
733 8 delete $self->{_insert_ids_afterEnd}{$id};
734 8 $self->{_found}{$id} = 1;
735 }
736 17 delete $self->{_watch_for};
737 }
738 } else {
739 26 $self->{_collect} .= $text;
740 }
741 }
742  
743 30 ▶sub end_document_handler {
Subroutine end_document_handler: called CC=1 SCAR=0.0
744 30 my ( $self, $text ) = @_;
745 30 $self->{_collect} .= $text;
746 }
747  
748 60 ▶sub comment_handler {
Subroutine comment_handler: called CC=12 SCAR=24.9
749 60 my ( $self, $text, $skip ) = @_;
750  
751 60 $self->{_collect} .= $skip;
752  
753 60 ▶ if ( exists $self->{_watch_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_watch_for"}) 17 43 60
754 17 ▶ if ( $self->{_watch_for} eq '<!--' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_watch_for'} eq '<!--') { } 7 10 17
755 7 delete $self->{_watch_for};
756 7 my $id = $self->{_watch_for_id};
757  
758 7 ▶ if ( exists $self->{_insert_ids_beforeEnd}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_insert_ids_beforeEnd"}{$id}) 4 3 7
759 4 $self->{_collect} .= $self->{_insert_ids_beforeEnd}{$id};
760 4 delete $self->{_insert_ids_beforeEnd}{$id};
761 4 $self->{_found}{$id} = 1;
762 }
763  
764 7 $self->{_collect} .= $text;
765  
766 7 ▶ if ( exists $self->{_insert_ids_afterEnd}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_insert_ids_afterEnd"}{$id}) 3 4 7
767 3 $self->{_collect} .= $self->{_insert_ids_afterEnd}{$id};
768 3 delete $self->{_insert_ids_afterEnd}{$id};
769 3 $self->{_found}{$id} = 1;
770 }
771  
772 } else {
773 10 $self->{_collect} .= $text;
774 }
775 17 return;
776 }
777  
778 43 my $id = lc $text;
779 43 $id =~ s/\s//g;
780  
781 43 ▶ if ( $id and exists $self->{_insert_ids_beforeBegin}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id and exists $self->{"_insert_ids_beforeBegin"}{$id}) 3 40 43
Condition66%2/3
$id and exists $self->{"_insert_ids_beforeBegin"}{$id}
!ll&&!rl&&r
0403
MC/DC50%1/2
$id and exists $self->{"_insert_ids_beforeBegin"}{$id}
$id exists $self->{"_insert_ids_beforeBegin"}{$id}
Truth table66%2/3
A and B
A= $idB= exists $self->{"_insert_ids_beforeBegin"}{$id}
ABresult
0X0
100
111
782 3 $self->{_collect} .= $self->{_insert_ids_beforeBegin}{$id};
783 3 delete $self->{_insert_ids_beforeBegin}{$id};
784 3 $self->{_found}{$id} = 1;
785  
786 }
787  
788 43 $self->{_collect} .= $text;
789 43 ▶ if ( $id and exists $self->{_insert_ids_afterBegin}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id and exists $self->{"_insert_ids_afterBegin"}{$id}) 3 40 43
Condition66%2/3
$id and exists $self->{"_insert_ids_afterBegin"}{$id}
!ll&&!rl&&r
0403
MC/DC50%1/2
$id and exists $self->{"_insert_ids_afterBegin"}{$id}
$id exists $self->{"_insert_ids_afterBegin"}{$id}
Truth table66%2/3
A and B
A= $idB= exists $self->{"_insert_ids_afterBegin"}{$id}
ABresult
0X0
100
111
790 3 $self->{_collect} .= $self->{_insert_ids_afterBegin}{$id};
791 3 delete $self->{_insert_ids_afterBegin}{$id};
792 3 $self->{_found}{$id} = 1;
793  
794 }
795  
796 43 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($id and exists $self->{"_insert_ids_afterEnd"}{$id} || exists $self->{"_insert_ids_beforeEnd"}{$id}) 36 7 43
Condition83%5/6
$id and exists $self->{"_insert_ids_afterEnd"}{$id} || exists $self->{"_insert_ids_beforeEnd"}{$id}
!ll&&!rl&&r
0367
exists $self->{"_insert_ids_afterEnd"}{$id} or exists $self->{"_insert_ids_beforeEnd"}{$id}
l!l&&r!l&&!r
3436
MC/DC66%2/3
$id and exists $self->{"_insert_ids_afterEnd"}{$id} || exists $self->{"_insert_ids_beforeEnd"}{$id}
$id exists $self->{"_insert_ids_afterEnd"}{$id} exists $self->{"_insert_ids_beforeEnd"}{$id}
Truth table75%3/4
A and B or C
A= $idB= exists $self->{"_insert_ids_afterEnd"}{$id}C= exists $self->{"_insert_ids_beforeEnd"}{$id}
ABCresult
0XX0
1000
11X1
1011
797 $id
798 and ( exists $self->{_insert_ids_afterEnd}{$id}
799 or exists $self->{_insert_ids_beforeEnd}{$id} )
800 )
801 {
802 36 return;
803 }
804  
805 7 $self->{_watch_for} = '<!--';
806 7 $self->{_watch_for_id} = $id;
807 }
808  
809 30 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
810 30 my ( $class, $args ) = @_;
811 30 my $self = HTML::Parser::new(
812 $class,
813 start_h =>
814 [ 'start_handler', "self,tagname, attr, text, skipped_text" ],
815 end_h => [ 'end_handler', "self,tagname, text, skipped_text" ],
816 end_document_h => [ 'end_document_handler', "self, skipped_text" ],
817 comment_h => [ 'comment_handler', 'self, text, skipped_text' ],
818 );
819  
820 30 $self->{_insert_ids_beforeBegin} = $args->{before_begin};
821 30 $self->{_insert_ids_afterBegin} = $args->{after_begin};
822 30 $self->{_insert_ids_beforeEnd} = $args->{before_end};
823 30 $self->{_insert_ids_afterEnd} = $args->{after_end};
824  
825 30 $self->{_collect} = '';
826 30 return $self;
827 }
828  
829 2 1;
830 __END__
↑ Summary Manipulator/Document.pm »