line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::HTML::Content::NoXPath; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.005_62; |
4
|
18
|
|
|
18
|
|
170
|
use strict; |
|
18
|
|
|
|
|
36
|
|
|
18
|
|
|
|
|
468
|
|
5
|
18
|
|
|
18
|
|
80
|
use File::Spec; |
|
18
|
|
|
|
|
28
|
|
|
18
|
|
|
|
|
405
|
|
6
|
18
|
|
|
18
|
|
268
|
use HTML::TokeParser; |
|
18
|
|
|
|
|
51
|
|
|
18
|
|
|
|
|
647
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# we want to stay compatible to 5.5 and use warnings if |
9
|
|
|
|
|
|
|
# we can |
10
|
18
|
|
|
18
|
|
96
|
eval 'use warnings;' if ($] >= 5.006); |
|
18
|
|
|
|
|
47
|
|
|
18
|
|
|
|
|
444
|
|
11
|
18
|
|
|
18
|
|
90
|
use vars qw( $HTML_PARSER_StripsTags $VERSION @exports ); |
|
18
|
|
|
|
|
25
|
|
|
18
|
|
|
|
|
2184
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.11'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
BEGIN { |
16
|
|
|
|
|
|
|
# Check whether HTML::Parser is v3 and delivers the comments starting |
17
|
|
|
|
|
|
|
# with the "; |
19
|
18
|
|
|
|
|
95
|
my $p = HTML::TokeParser->new(\$HTML); |
20
|
18
|
|
|
|
|
2872
|
my ($type,$text) = @{$p->get_token()}; |
|
18
|
|
|
|
|
105
|
|
21
|
18
|
50
|
|
|
|
756
|
if ($text eq "") { |
22
|
18
|
|
|
|
|
1614
|
$HTML_PARSER_StripsTags = 0 |
23
|
|
|
|
|
|
|
} else { |
24
|
0
|
|
|
|
|
0
|
$HTML_PARSER_StripsTags = 1 |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# import what we need |
29
|
18
|
|
|
18
|
|
105
|
{ no strict 'refs'; |
|
18
|
|
|
|
|
28
|
|
|
18
|
|
|
|
|
17114
|
|
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
|
|
2780
|
my ($text,$template) = @_; |
39
|
48
|
50
|
|
|
|
225
|
$text =~ s/^$/$1/ unless $HTML_PARSER_StripsTags; |
40
|
48
|
100
|
|
|
|
123
|
unless (ref $template eq "Regexp") { |
41
|
29
|
|
|
|
|
116
|
$text =~ s/^\s*(.*?)\s*$/$1/; |
42
|
29
|
|
|
|
|
103
|
$template =~ s/^\s*(.*?)\s*$/$1/; |
43
|
|
|
|
|
|
|
}; |
44
|
48
|
|
|
|
|
113
|
return __dwim_compare($text, $template); |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub __count_comments { |
48
|
32
|
|
|
32
|
|
10207
|
my ($HTML,$comment) = @_; |
49
|
32
|
|
|
|
|
43
|
my $result = 0; |
50
|
32
|
|
|
|
|
47
|
my $seen = []; |
51
|
|
|
|
|
|
|
|
52
|
32
|
|
|
|
|
86
|
my $p = HTML::TokeParser->new(\$HTML); |
53
|
32
|
|
|
|
|
3362
|
my $token; |
54
|
32
|
|
|
|
|
73
|
while ($token = $p->get_token) { |
55
|
147
|
|
|
|
|
1884
|
my ($type,$text) = @$token; |
56
|
147
|
100
|
|
|
|
295
|
if ($type eq "C") { |
57
|
41
|
|
|
|
|
70
|
push @$seen, $token->[1]; |
58
|
41
|
100
|
|
|
|
64
|
$result++ if __match_comment($text,$comment); |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
32
|
|
|
|
|
365
|
return ($result, $seen); |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub __match_text { |
66
|
37
|
|
|
37
|
|
2743
|
my ($text,$template) = @_; |
67
|
37
|
100
|
|
|
|
67
|
unless (ref $template eq "Regexp") { |
68
|
16
|
|
|
|
|
85
|
$text =~ s/^\s*(.*?)\s*$/$1/; |
69
|
16
|
|
|
|
|
63
|
$template =~ s/^\s*(.*?)\s*$/$1/; |
70
|
|
|
|
|
|
|
}; |
71
|
37
|
|
|
|
|
75
|
return __dwim_compare($text, $template); |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub __count_text { |
75
|
19
|
|
|
19
|
|
5067
|
my ($HTML,$text) = @_; |
76
|
19
|
|
|
|
|
30
|
my $result = 0; |
77
|
19
|
|
|
|
|
26
|
my $seen = []; |
78
|
|
|
|
|
|
|
|
79
|
19
|
|
|
|
|
54
|
my $p = HTML::TokeParser->new(\$HTML); |
80
|
19
|
|
|
|
|
1961
|
$p->unbroken_text(1); |
81
|
|
|
|
|
|
|
|
82
|
19
|
|
|
|
|
25
|
my $token; |
83
|
19
|
|
|
|
|
42
|
while ($token = $p->get_token) { |
84
|
82
|
|
|
|
|
1523
|
my ($type,$foundtext) = @$token; |
85
|
82
|
100
|
|
|
|
158
|
if ($type eq "T") { |
86
|
30
|
|
|
|
|
46
|
push @$seen, $token->[1]; |
87
|
30
|
100
|
|
|
|
66
|
$result++ if __match_text($foundtext,$text); |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
|
91
|
19
|
|
|
|
|
236
|
return $result,$seen; |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub __match { |
95
|
67
|
|
|
67
|
|
3590
|
my ($attrs,$currattr,$key) = @_; |
96
|
67
|
|
|
|
|
87
|
my $result = 1; |
97
|
|
|
|
|
|
|
|
98
|
67
|
100
|
|
|
|
118
|
if (exists $currattr->{$key}) { |
99
|
61
|
100
|
|
|
|
97
|
if (! defined $attrs->{$key}) { |
100
|
4
|
|
|
|
|
6
|
$result = 0; # We don't want to see this attribute here |
101
|
|
|
|
|
|
|
} else { |
102
|
57
|
100
|
|
|
|
124
|
$result = 0 unless __dwim_compare($currattr->{$key}, $attrs->{$key}); |
103
|
|
|
|
|
|
|
}; |
104
|
|
|
|
|
|
|
} else { |
105
|
6
|
100
|
|
|
|
11
|
if (! defined $attrs->{$key}) { |
106
|
2
|
50
|
|
|
|
7
|
$result = 0 if (exists $currattr->{$key}); |
107
|
|
|
|
|
|
|
} else { |
108
|
4
|
|
|
|
|
8
|
$result = 0; |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
}; |
111
|
67
|
|
|
|
|
162
|
return $result; |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub __count_tags { |
115
|
57
|
|
|
57
|
|
7218
|
my ($HTML,$tag,$attrref) = @_; |
116
|
57
|
50
|
|
|
|
111
|
$attrref = {} unless defined $attrref; |
117
|
|
|
|
|
|
|
return ('skip','XML::LibXML or XML::XPath not loaded') |
118
|
57
|
100
|
|
|
|
128
|
if exists $attrref->{_content}; |
119
|
|
|
|
|
|
|
|
120
|
51
|
|
|
|
|
62
|
my $result = 0; |
121
|
51
|
|
|
|
|
82
|
$tag = lc $tag; |
122
|
|
|
|
|
|
|
|
123
|
51
|
|
|
|
|
139
|
my $p = HTML::TokeParser->new(\$HTML); |
124
|
51
|
|
|
|
|
5295
|
my $token; |
125
|
|
|
|
|
|
|
my @seen; |
126
|
51
|
|
|
|
|
111
|
while ($token = $p->get_token) { |
127
|
290
|
|
|
|
|
3535
|
my ($type,$currtag,$currattr,$attrseq,$origtext) = @$token; |
128
|
290
|
100
|
100
|
|
|
743
|
if ($type eq "S" && $tag eq $currtag) { |
129
|
55
|
|
|
|
|
121
|
my (@keys) = keys %$attrref; |
130
|
55
|
|
|
|
|
95
|
my $key; |
131
|
55
|
|
|
|
|
68
|
my $complete = 1; |
132
|
55
|
|
|
|
|
77
|
foreach $key (@keys) { |
133
|
60
|
100
|
|
|
|
127
|
$complete = __match($attrref,$currattr,$key) if $complete; |
134
|
|
|
|
|
|
|
}; |
135
|
55
|
|
|
|
|
67
|
$result += $complete; |
136
|
|
|
|
|
|
|
# Now munge the thing to resemble what the XPath variant returns : |
137
|
55
|
|
|
|
|
157
|
push @seen, $token->[4]; |
138
|
|
|
|
|
|
|
}; |
139
|
|
|
|
|
|
|
}; |
140
|
|
|
|
|
|
|
|
141
|
51
|
|
|
|
|
567
|
return $result,\@seen; |
142
|
|
|
|
|
|
|
}; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub __match_declaration { |
145
|
11
|
|
|
11
|
|
2740
|
my ($text,$template) = @_; |
146
|
11
|
50
|
|
|
|
49
|
$text =~ s/^$/$1/ unless $HTML_PARSER_StripsTags; |
147
|
11
|
100
|
|
|
|
30
|
unless (ref $template eq "Regexp") { |
148
|
3
|
|
|
|
|
16
|
$text =~ s/^\s*(.*?)\s*$/$1/; |
149
|
3
|
|
|
|
|
16
|
$template =~ s/^\s*(.*?)\s*$/$1/; |
150
|
|
|
|
|
|
|
}; |
151
|
11
|
|
|
|
|
27
|
return __dwim_compare($text, $template); |
152
|
|
|
|
|
|
|
}; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub __count_declarations { |
155
|
4
|
|
|
4
|
|
7
|
my ($HTML,$doctype) = @_; |
156
|
4
|
|
|
|
|
6
|
my $result = 0; |
157
|
4
|
|
|
|
|
6
|
my $seen = []; |
158
|
|
|
|
|
|
|
|
159
|
4
|
|
|
|
|
12
|
my $p = HTML::TokeParser->new(\$HTML); |
160
|
4
|
|
|
|
|
579
|
my $token; |
161
|
4
|
|
|
|
|
9
|
while ($token = $p->get_token) { |
162
|
8
|
|
|
|
|
248
|
my ($type,$text) = @$token; |
163
|
8
|
100
|
|
|
|
22
|
if ($type eq "D") { |
164
|
4
|
|
|
|
|
6
|
push @$seen, $text; |
165
|
4
|
100
|
|
|
|
8
|
$result++ if __match_declaration($text,$doctype); |
166
|
|
|
|
|
|
|
}; |
167
|
|
|
|
|
|
|
}; |
168
|
|
|
|
|
|
|
|
169
|
4
|
|
|
|
|
79
|
return $result, $seen; |
170
|
|
|
|
|
|
|
}; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub import { |
173
|
29
|
|
|
29
|
|
95
|
goto &install; |
174
|
|
|
|
|
|
|
}; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub install { |
177
|
30
|
|
|
30
|
0
|
977
|
for (@exports) { |
178
|
18
|
|
|
18
|
|
134
|
no strict 'refs'; |
|
18
|
|
|
|
|
54
|
|
|
18
|
|
|
|
|
1566
|
|
179
|
240
|
|
|
|
|
306
|
*{"Test::HTML::Content::$_"} = *{"Test::HTML::Content::NoXPath::$_"}; |
|
240
|
|
|
|
|
1658
|
|
|
240
|
|
|
|
|
487
|
|
180
|
|
|
|
|
|
|
}; |
181
|
30
|
|
|
|
|
1208
|
$Test::HTML::Content::can_xpath = 0; |
182
|
|
|
|
|
|
|
}; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
__END__ |