line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::HTML::Content::NoXPath; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.005_62; |
4
|
21
|
|
|
21
|
|
2090
|
use strict; |
|
21
|
|
|
|
|
49
|
|
|
21
|
|
|
|
|
1174
|
|
5
|
21
|
|
|
21
|
|
122
|
use File::Spec; |
|
21
|
|
|
|
|
49
|
|
|
21
|
|
|
|
|
537
|
|
6
|
21
|
|
|
21
|
|
115
|
use HTML::TokeParser; |
|
21
|
|
|
|
|
45
|
|
|
21
|
|
|
|
|
879
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# we want to stay compatible to 5.5 and use warnings if |
9
|
|
|
|
|
|
|
# we can |
10
|
21
|
|
|
21
|
|
142
|
eval 'use warnings;' if ($] >= 5.006); |
|
21
|
|
|
|
|
447
|
|
|
21
|
|
|
|
|
644
|
|
11
|
21
|
|
|
21
|
|
121
|
use vars qw( $HTML_PARSER_StripsTags $VERSION @exports ); |
|
21
|
|
|
|
|
79
|
|
|
21
|
|
|
|
|
3891
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.09'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
BEGIN { |
16
|
|
|
|
|
|
|
# Check whether HTML::Parser is v3 and delivers the comments starting |
17
|
|
|
|
|
|
|
# with the "; |
19
|
21
|
|
|
|
|
175
|
my $p = HTML::TokeParser->new(\$HTML); |
20
|
21
|
|
|
|
|
5582
|
my ($type,$text) = @{$p->get_token()}; |
|
21
|
|
|
|
|
201
|
|
21
|
21
|
50
|
|
|
|
1396
|
if ($text eq "") { |
22
|
21
|
|
|
|
|
1023
|
$HTML_PARSER_StripsTags = 0 |
23
|
|
|
|
|
|
|
} else { |
24
|
0
|
|
|
|
|
0
|
$HTML_PARSER_StripsTags = 1 |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# import what we need |
29
|
21
|
|
|
21
|
|
128
|
{ no strict 'refs'; |
|
21
|
|
|
|
|
41
|
|
|
21
|
|
|
|
|
38992
|
|
30
|
|
|
|
|
|
|
*{$_} = *{"Test::HTML::Content::$_"} |
31
|
|
|
|
|
|
|
for qw( __dwim_compare __output_diag __invalid_html ); |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
@exports = qw( __match_comment __count_comments __match_text __count_text |
35
|
|
|
|
|
|
|
__match __count_tags __match_declaration __count_declarations ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub __match_comment { |
38
|
48
|
|
|
48
|
|
6627
|
my ($text,$template) = @_; |
39
|
48
|
50
|
|
|
|
312
|
$text =~ s/^$/$1/ unless $HTML_PARSER_StripsTags; |
40
|
48
|
100
|
|
|
|
139
|
unless (ref $template eq "Regexp") { |
41
|
29
|
|
|
|
|
477
|
$text =~ s/^\s*(.*?)\s*$/$1/; |
42
|
29
|
|
|
|
|
239
|
$template =~ s/^\s*(.*?)\s*$/$1/; |
43
|
|
|
|
|
|
|
}; |
44
|
48
|
|
|
|
|
180
|
return __dwim_compare($text, $template); |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub __count_comments { |
48
|
32
|
|
|
32
|
|
27758
|
my ($HTML,$comment) = @_; |
49
|
32
|
|
|
|
|
87
|
my $result = 0; |
50
|
32
|
|
|
|
|
53
|
my $seen = []; |
51
|
|
|
|
|
|
|
|
52
|
32
|
|
|
|
|
1604
|
my $p = HTML::TokeParser->new(\$HTML); |
53
|
32
|
|
|
|
|
5883
|
my $token; |
54
|
32
|
|
|
|
|
198
|
while ($token = $p->get_token) { |
55
|
147
|
|
|
|
|
3007
|
my ($type,$text) = @$token; |
56
|
147
|
100
|
|
|
|
553
|
if ($type eq "C") { |
57
|
41
|
|
|
|
|
72
|
push @$seen, $token->[1]; |
58
|
41
|
100
|
|
|
|
99
|
$result++ if __match_comment($text,$comment); |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
32
|
|
|
|
|
535
|
return ($result, $seen); |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub __match_text { |
66
|
37
|
|
|
37
|
|
6841
|
my ($text,$template) = @_; |
67
|
37
|
100
|
|
|
|
92
|
unless (ref $template eq "Regexp") { |
68
|
16
|
|
|
|
|
105
|
$text =~ s/^\s*(.*?)\s*$/$1/; |
69
|
16
|
|
|
|
|
84
|
$template =~ s/^\s*(.*?)\s*$/$1/; |
70
|
|
|
|
|
|
|
}; |
71
|
37
|
|
|
|
|
111
|
return __dwim_compare($text, $template); |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub __count_text { |
75
|
19
|
|
|
19
|
|
4484
|
my ($HTML,$text) = @_; |
76
|
19
|
|
|
|
|
31
|
my $result = 0; |
77
|
19
|
|
|
|
|
39
|
my $seen = []; |
78
|
|
|
|
|
|
|
|
79
|
19
|
|
|
|
|
80
|
my $p = HTML::TokeParser->new(\$HTML); |
80
|
19
|
|
|
|
|
2337
|
$p->unbroken_text(1); |
81
|
|
|
|
|
|
|
|
82
|
19
|
|
|
|
|
21
|
my $token; |
83
|
19
|
|
|
|
|
59
|
while ($token = $p->get_token) { |
84
|
82
|
|
|
|
|
3035
|
my ($type,$foundtext) = @$token; |
85
|
82
|
100
|
|
|
|
265
|
if ($type eq "T") { |
86
|
30
|
|
|
|
|
49
|
push @$seen, $token->[1]; |
87
|
30
|
100
|
|
|
|
69
|
$result++ if __match_text($foundtext,$text); |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
|
91
|
19
|
|
|
|
|
296
|
return $result,$seen; |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub __match { |
95
|
72
|
|
|
72
|
|
7381
|
my ($attrs,$currattr,$key) = @_; |
96
|
72
|
|
|
|
|
237
|
my $result = 1; |
97
|
|
|
|
|
|
|
|
98
|
72
|
100
|
|
|
|
175
|
if (exists $currattr->{$key}) { |
99
|
66
|
100
|
|
|
|
146
|
if (! defined $attrs->{$key}) { |
100
|
4
|
|
|
|
|
10
|
$result = 0; # We don't want to see this attribute here |
101
|
|
|
|
|
|
|
} else { |
102
|
62
|
100
|
|
|
|
211
|
$result = 0 unless __dwim_compare($currattr->{$key}, $attrs->{$key}); |
103
|
|
|
|
|
|
|
}; |
104
|
|
|
|
|
|
|
} else { |
105
|
6
|
100
|
|
|
|
20
|
if (! defined $attrs->{$key}) { |
106
|
2
|
50
|
|
|
|
10
|
$result = 0 if (exists $currattr->{$key}); |
107
|
|
|
|
|
|
|
} else { |
108
|
4
|
|
|
|
|
10
|
$result = 0; |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
}; |
111
|
72
|
|
|
|
|
1359
|
return $result; |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub __count_tags { |
115
|
63
|
|
|
63
|
|
24506
|
my ($HTML,$tag,$attrref) = @_; |
116
|
63
|
50
|
|
|
|
308
|
$attrref = {} unless defined $attrref; |
117
|
63
|
100
|
|
|
|
193
|
return ('skip','XML::LibXML or XML::XPath not loaded') |
118
|
|
|
|
|
|
|
if exists $attrref->{_content}; |
119
|
|
|
|
|
|
|
|
120
|
54
|
|
|
|
|
74
|
my $result = 0; |
121
|
54
|
|
|
|
|
97
|
$tag = lc $tag; |
122
|
|
|
|
|
|
|
|
123
|
54
|
|
|
|
|
242
|
my $p = HTML::TokeParser->new(\$HTML); |
124
|
54
|
|
|
|
|
23366
|
my $token; |
125
|
|
|
|
|
|
|
my @seen; |
126
|
54
|
|
|
|
|
193
|
while ($token = $p->get_token) { |
127
|
311
|
|
|
|
|
6716
|
my ($type,$currtag,$currattr,$attrseq,$origtext) = @$token; |
128
|
311
|
100
|
100
|
|
|
2036
|
if ($type eq "S" && $tag eq $currtag) { |
129
|
58
|
|
|
|
|
479
|
my (@keys) = keys %$attrref; |
130
|
58
|
|
|
|
|
77
|
my $key; |
131
|
58
|
|
|
|
|
124
|
my $complete = 1; |
132
|
58
|
|
|
|
|
101
|
foreach $key (@keys) { |
133
|
63
|
50
|
|
|
|
198
|
$complete = __match($attrref,$currattr,$key) if $complete; |
134
|
|
|
|
|
|
|
}; |
135
|
58
|
|
|
|
|
91
|
$result += $complete; |
136
|
|
|
|
|
|
|
# Now munge the thing to resemble what the XPath variant returns : |
137
|
58
|
|
|
|
|
272
|
push @seen, $token->[4]; |
138
|
|
|
|
|
|
|
}; |
139
|
|
|
|
|
|
|
}; |
140
|
|
|
|
|
|
|
|
141
|
54
|
|
|
|
|
1000
|
return $result,\@seen; |
142
|
|
|
|
|
|
|
}; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub __match_declaration { |
145
|
11
|
|
|
11
|
|
5375
|
my ($text,$template) = @_; |
146
|
11
|
50
|
|
|
|
62
|
$text =~ s/^$/$1/ unless $HTML_PARSER_StripsTags; |
147
|
11
|
100
|
|
|
|
37
|
unless (ref $template eq "Regexp") { |
148
|
3
|
|
|
|
|
26
|
$text =~ s/^\s*(.*?)\s*$/$1/; |
149
|
3
|
|
|
|
|
25
|
$template =~ s/^\s*(.*?)\s*$/$1/; |
150
|
|
|
|
|
|
|
}; |
151
|
11
|
|
|
|
|
41
|
return __dwim_compare($text, $template); |
152
|
|
|
|
|
|
|
}; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub __count_declarations { |
155
|
4
|
|
|
4
|
|
10
|
my ($HTML,$doctype) = @_; |
156
|
4
|
|
|
|
|
6
|
my $result = 0; |
157
|
4
|
|
|
|
|
7
|
my $seen = []; |
158
|
|
|
|
|
|
|
|
159
|
4
|
|
|
|
|
26
|
my $p = HTML::TokeParser->new(\$HTML); |
160
|
4
|
|
|
|
|
550
|
my $token; |
161
|
4
|
|
|
|
|
15
|
while ($token = $p->get_token) { |
162
|
8
|
|
|
|
|
190
|
my ($type,$text) = @$token; |
163
|
8
|
100
|
|
|
|
28
|
if ($type eq "D") { |
164
|
4
|
|
|
|
|
7
|
push @$seen, $text; |
165
|
4
|
100
|
|
|
|
11
|
$result++ if __match_declaration($text,$doctype); |
166
|
|
|
|
|
|
|
}; |
167
|
|
|
|
|
|
|
}; |
168
|
|
|
|
|
|
|
|
169
|
4
|
|
|
|
|
61
|
return $result, $seen; |
170
|
|
|
|
|
|
|
}; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub import { |
173
|
32
|
|
|
32
|
|
350
|
goto &install; |
174
|
|
|
|
|
|
|
}; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub install { |
177
|
33
|
|
|
33
|
0
|
767
|
for (@exports) { |
178
|
21
|
|
|
21
|
|
169
|
no strict 'refs'; |
|
21
|
|
|
|
|
42
|
|
|
21
|
|
|
|
|
2982
|
|
179
|
264
|
|
|
|
|
316
|
*{"Test::HTML::Content::$_"} = *{"Test::HTML::Content::NoXPath::$_"}; |
|
264
|
|
|
|
|
3136
|
|
|
264
|
|
|
|
|
731
|
|
180
|
|
|
|
|
|
|
}; |
181
|
33
|
|
|
|
|
3199
|
$Test::HTML::Content::can_xpath = 0; |
182
|
|
|
|
|
|
|
}; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
__END__ |