line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::TagUtil; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
##HTML::TagUtil |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
24799
|
use 5.008001; #Need 5.8.1. |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
42
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
49
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
1
|
|
|
1
|
|
997
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
1983
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
15
|
|
|
|
|
|
|
tagged |
16
|
|
|
|
|
|
|
opentagged |
17
|
|
|
|
|
|
|
closetagged |
18
|
|
|
|
|
|
|
tagpos |
19
|
|
|
|
|
|
|
string |
20
|
|
|
|
|
|
|
comment |
21
|
|
|
|
|
|
|
) ] ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); #allow all public methods to export. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = '1.43'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
##package variable to set whether to allow hyphens in comments. |
30
|
|
|
|
|
|
|
##Note: this is a *hack* to avoid having to deal with putting it in the |
31
|
|
|
|
|
|
|
##invocant's hashref here. (Couldn't figure out how to do it right. :-) |
32
|
|
|
|
|
|
|
## still looks the same to the user though, if they call the allow_hyphen |
33
|
|
|
|
|
|
|
##method. |
34
|
|
|
|
|
|
|
our $Allow_Hyphen = 0; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#$file will someday be available for checking. |
39
|
|
|
|
|
|
|
#my $file; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
########################### |
42
|
|
|
|
|
|
|
#####Class Constructor##### |
43
|
|
|
|
|
|
|
########################### |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
0
|
|
|
0
|
1
|
|
my $self = { |
47
|
|
|
|
|
|
|
string => shift, |
48
|
|
|
|
|
|
|
tag => shift, |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
0
|
|
|
|
$self->{string } ||= ''; |
52
|
0
|
|
0
|
|
|
|
$self->{tag } ||= ''; |
53
|
|
|
|
|
|
|
# $file = shift; |
54
|
0
|
|
|
|
|
|
bless $self, 'HTML::TagUtil'; |
55
|
0
|
|
|
|
|
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#################################### |
59
|
|
|
|
|
|
|
##########PRIVATE METHODS########### |
60
|
|
|
|
|
|
|
#################################### |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
## |
63
|
|
|
|
|
|
|
## Private method that does the actual matching for tagged. |
64
|
|
|
|
|
|
|
## |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _is_fully_tagged { |
67
|
0
|
|
|
0
|
|
|
my $self = shift; |
68
|
0
|
|
0
|
|
|
|
my $arg = shift || $_; |
69
|
0
|
0
|
|
|
|
|
if ($arg =~ /<(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (\/)?)?\s*>.*<\/(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (\/)?)?\s*/) { |
70
|
0
|
|
|
|
|
|
return 1; |
71
|
|
|
|
|
|
|
} else { |
72
|
0
|
|
|
|
|
|
return 0; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
0
|
|
|
|
|
$_ = $arg if ($arg); |
75
|
0
|
0
|
|
|
|
|
$self->{string} = $arg if ($arg); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
## |
79
|
|
|
|
|
|
|
## Private method that matches for opentagged. |
80
|
|
|
|
|
|
|
## |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _is_open_tagged { |
83
|
0
|
|
|
0
|
|
|
my $self = shift; |
84
|
0
|
|
0
|
|
|
|
my $arg = shift || $_; |
85
|
0
|
0
|
|
|
|
|
if ($arg =~ /<(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (\/)?)?\s*>/) { |
86
|
0
|
|
|
|
|
|
return 1; |
87
|
|
|
|
|
|
|
} else { |
88
|
0
|
|
|
|
|
|
return 0; |
89
|
|
|
|
|
|
|
} |
90
|
0
|
0
|
|
|
|
|
$_ = $arg if ($arg); |
91
|
0
|
0
|
|
|
|
|
$self->{string} = $arg if ($arg); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
## |
95
|
|
|
|
|
|
|
## Private method that matches for closetagged. |
96
|
|
|
|
|
|
|
## |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _is_close_tagged { |
99
|
0
|
|
|
0
|
|
|
my $self = shift; |
100
|
0
|
|
0
|
|
|
|
my $arg = shift || $_; |
101
|
0
|
0
|
|
|
|
|
if ($arg =~ /<\/([a-zA-Z])+\s*>/) { |
102
|
0
|
|
|
|
|
|
return 1; |
103
|
|
|
|
|
|
|
} else { |
104
|
0
|
|
|
|
|
|
return 0; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
0
|
|
|
|
|
$_ = $arg if ($arg); |
107
|
0
|
0
|
|
|
|
|
$self->{string} = $arg if ($arg); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
## |
111
|
|
|
|
|
|
|
## Private method that matches for empty. |
112
|
|
|
|
|
|
|
## |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _is_empty_element { |
115
|
0
|
|
|
0
|
|
|
my $self = shift; |
116
|
0
|
|
0
|
|
|
|
my $arg = shift || $_; |
117
|
0
|
0
|
|
|
|
|
if ($arg =~ /<(([a-zA-Z])+((\s+\w+)=?("?.+"?)?){0,})(\s*\/)\s*>/) { |
118
|
0
|
|
|
|
|
|
return 1; |
119
|
|
|
|
|
|
|
} else { |
120
|
0
|
|
|
|
|
|
return 0; |
121
|
|
|
|
|
|
|
} |
122
|
0
|
0
|
|
|
|
|
$_ = $arg if ($arg); |
123
|
0
|
0
|
|
|
|
|
$self->{string} = $arg if ($arg); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
## |
127
|
|
|
|
|
|
|
## Private method for comment(). |
128
|
|
|
|
|
|
|
## |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _is_comment { |
131
|
0
|
|
|
0
|
|
|
my $self = shift; |
132
|
0
|
|
0
|
|
|
|
my $arg = shift || $_; |
133
|
|
|
|
|
|
|
|
134
|
0
|
0
|
|
|
|
|
if ($Allow_Hyphen) { |
135
|
0
|
0
|
|
|
|
|
if ($arg =~ //) { |
136
|
0
|
|
|
|
|
|
return 1; |
137
|
|
|
|
|
|
|
} else { |
138
|
0
|
|
|
|
|
|
return 0; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} else { |
141
|
0
|
0
|
|
|
|
|
if ($arg =~ //) { |
142
|
0
|
|
|
|
|
|
return 1; |
143
|
|
|
|
|
|
|
} else { |
144
|
0
|
|
|
|
|
|
return 0; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
0
|
0
|
|
|
|
|
$_ = $arg if ($arg); |
148
|
0
|
0
|
|
|
|
|
$self->{string} = $arg if ($arg); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
#################################### |
152
|
|
|
|
|
|
|
##########PUBLIC METHODS############ |
153
|
|
|
|
|
|
|
#################################### |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
## |
156
|
|
|
|
|
|
|
## Get/set methods. |
157
|
|
|
|
|
|
|
## one for getting/setting the string(currenly does not work), and one for |
158
|
|
|
|
|
|
|
## gettin/setting whether to allow hyphens in comments. |
159
|
|
|
|
|
|
|
## |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub string { |
162
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
163
|
0
|
|
|
|
|
|
my $string = $self->{string}; |
164
|
0
|
0
|
|
|
|
|
$string = shift unless ($self->{string}); |
165
|
0
|
0
|
|
|
|
|
return $self->{string} unless ($string); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub allow_hyphen { |
169
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
170
|
0
|
|
|
|
|
|
my $arg = shift; |
171
|
0
|
|
|
|
|
|
$Allow_Hyphen = $arg; |
172
|
0
|
0
|
|
|
|
|
return $Allow_Hyphen unless ($arg); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub tagged { |
176
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
177
|
0
|
|
0
|
|
|
|
my $string = shift || $self->{string} || $_; #string to look at. |
178
|
|
|
|
|
|
|
##check to see if it has both a start tag and an end tag. |
179
|
0
|
0
|
|
|
|
|
if (_is_fully_tagged ($self->{string})) { |
180
|
|
|
|
|
|
|
##set some variables just in case. |
181
|
0
|
|
|
|
|
|
my $tag = $1; |
182
|
0
|
|
|
|
|
|
my $element = $2; |
183
|
0
|
|
|
|
|
|
my $fullattr = $3; |
184
|
0
|
|
|
|
|
|
my $attrname = $4; |
185
|
0
|
|
|
|
|
|
my $attrvalue = $5; |
186
|
0
|
|
|
|
|
|
return 1; |
187
|
|
|
|
|
|
|
} else { |
188
|
0
|
|
|
|
|
|
return 0; |
189
|
|
|
|
|
|
|
} |
190
|
0
|
0
|
|
|
|
|
$self->{string} = $string if ($string); |
191
|
0
|
0
|
|
|
|
|
$_ = $self->{string} if ($self->{string}); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub opentagged { |
195
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
196
|
0
|
|
0
|
|
|
|
my $string = shift || $self->{string} || $_; #string to look at. |
197
|
|
|
|
|
|
|
##check to see if it at least has a start tag. |
198
|
0
|
0
|
|
|
|
|
if (_is_open_tagged ($string)) { |
199
|
|
|
|
|
|
|
##regexp vars. |
200
|
0
|
|
|
|
|
|
my $tag = $1; |
201
|
0
|
|
|
|
|
|
my $element = $2; |
202
|
0
|
|
|
|
|
|
my $fullattr = $3; |
203
|
0
|
|
|
|
|
|
my $attrname = $4; |
204
|
0
|
|
|
|
|
|
my $attrvalue = $5; |
205
|
0
|
|
|
|
|
|
return 1; |
206
|
|
|
|
|
|
|
} else { |
207
|
0
|
|
|
|
|
|
return 0; |
208
|
|
|
|
|
|
|
} |
209
|
0
|
0
|
|
|
|
|
$self->{string} = $string if ($string); |
210
|
0
|
0
|
|
|
|
|
$_ = $self->{string} if ($self->{string}); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub closetagged { |
214
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
215
|
0
|
|
0
|
|
|
|
my $string = shift || $self->{string} || $_; #string to look at. |
216
|
|
|
|
|
|
|
##check to see if it at least has an end tag. |
217
|
0
|
0
|
|
|
|
|
if (_is_close_tagged ($string)) { |
218
|
|
|
|
|
|
|
##regexp vars. |
219
|
0
|
|
|
|
|
|
my $tag = $1; |
220
|
0
|
|
|
|
|
|
my $element = $2; |
221
|
0
|
|
|
|
|
|
my $fullattr = $3; |
222
|
0
|
|
|
|
|
|
my $attrname = $4; |
223
|
0
|
|
|
|
|
|
my $attrvalue = $5; |
224
|
0
|
|
|
|
|
|
return 1; |
225
|
|
|
|
|
|
|
} else { |
226
|
0
|
|
|
|
|
|
return 0; |
227
|
|
|
|
|
|
|
} |
228
|
0
|
0
|
|
|
|
|
$self->{string} = $string if ($string); |
229
|
0
|
0
|
|
|
|
|
$_ = $self->{string} if ($self->{string}); |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub tagpos { |
233
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
234
|
0
|
|
0
|
|
|
|
my $string = shift || $self->{string} || $_; #string to look at. |
235
|
0
|
|
0
|
|
|
|
my $tag = shift || $self->{tag} || $_; #tag to look for. |
236
|
0
|
|
0
|
|
|
|
my $offset = shift || 0; # offset. |
237
|
0
|
0
|
|
|
|
|
$tag = '<' . $tag . '>' if ($tag !~ /(<(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (\/)?)?\s*>|<\/([a-zA-Z])+\s*>)/); |
238
|
0
|
|
|
|
|
|
return index ($string, $tag, $offset) + 1; |
239
|
0
|
0
|
|
|
|
|
$self->{string} = $string if ($string); |
240
|
0
|
0
|
|
|
|
|
$self->{tag } = $tag if ($tag); |
241
|
0
|
0
|
|
|
|
|
$_ = $self->{string} if ($self->{string}); |
242
|
0
|
0
|
|
|
|
|
$_ .= "||$tag" if ($self->{tag}); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub empty { |
246
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
247
|
0
|
|
0
|
|
|
|
my $string = shift || $self->{string} || $_; |
248
|
0
|
0
|
|
|
|
|
if (_is_empty_element ($string)) { |
249
|
0
|
|
|
|
|
|
return 1; |
250
|
0
|
|
|
|
|
|
my $tag = $1; |
251
|
0
|
|
|
|
|
|
my $element = $2; |
252
|
0
|
|
|
|
|
|
my $fullattr = $3; |
253
|
0
|
|
|
|
|
|
my $attrname = $4; |
254
|
0
|
|
|
|
|
|
my $attrvalue = $5; |
255
|
|
|
|
|
|
|
} else { |
256
|
0
|
|
|
|
|
|
return 0; |
257
|
|
|
|
|
|
|
} |
258
|
0
|
0
|
|
|
|
|
$self->{string} = $string if ($string); |
259
|
0
|
0
|
|
|
|
|
$_ = $self->{string} if ($self->{string}); |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
sub comment { |
263
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
264
|
0
|
|
0
|
|
|
|
my $string = shift || $self->{string} || $_; |
265
|
0
|
0
|
|
|
|
|
if (_is_comment($string)) { |
266
|
0
|
|
|
|
|
|
my $tag = $1; |
267
|
0
|
|
|
|
|
|
my $element = $2; |
268
|
0
|
|
|
|
|
|
my $fullattr = $3; |
269
|
0
|
|
|
|
|
|
my $attrname = $4; |
270
|
0
|
|
|
|
|
|
my $attrvalue = $5; |
271
|
0
|
|
|
|
|
|
return 1; |
272
|
|
|
|
|
|
|
} else { |
273
|
0
|
|
|
|
|
|
return 0; |
274
|
|
|
|
|
|
|
} |
275
|
0
|
0
|
|
|
|
|
$self->{string} = $string if ($string); |
276
|
0
|
0
|
|
|
|
|
$_ = $self->{string} if ($self->{string}); |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
1; |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
__END__ |