blib/lib/HTML/TagUtil.pm

filter: Statementstmt 13.4% 19 / 141 Branchbran 0.0% 0 / 80 Conditioncond 0.0% 0 / 63 MC/DCmcdc 0.0% 0 / 34 Subroutinesub 22.2% 4 / 18 Podpod 77.7% 7 / 9 totaltotal 8.7% 30 / 345 CC 63 SCAR 38.6
CC
63
Cov
7%
tagpos
132.0
_is_comment
56.0
tagged
42.0
CRAP 47.4
↑ Summary
1 package HTML::TagUtil;
2  
3 ##HTML::TagUtil
4  
5 1 ▶use 5.008001; #Need 5.8.1.
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 require Exporter;
10 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our @ISA = qw(Exporter);
13  
14 1 our %EXPORT_TAGS = ( 'all' => [ qw(
15 tagged
16 opentagged
17 closetagged
18 tagpos
19 string
20 comment
21 ) ] );
22  
23 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); #allow all public methods to export.
24  
25  
26  
27 1 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 1 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 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
46 0 my $self = {
47 string => shift,
48 tag => shift,
49 };
50  
51 0 ▶ $self->{string } ||= '';
Condition0%0/2
$self->{"string"} ||= ""
l!l
00
MC/DC0%0/1
$self->{"string"} ||= ""
$self->{"string"}
Truth table0%0/2
A
A= $self->{"string"}
Aresult
11
00
52 0 ▶ $self->{tag } ||= '';
Condition0%0/2
$self->{"tag"} ||= ""
l!l
00
MC/DC0%0/1
$self->{"tag"} ||= ""
$self->{"tag"}
Truth table0%0/2
A
A= $self->{"tag"}
Aresult
11
00
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 0 ▶sub _is_fully_tagged {
Subroutine _is_fully_tagged: not called CC=5 SCAR=34.0
67 0 my $self = shift;
68 0 ▶ my $arg = shift || $_;
Condition0%0/3
shift() || $_
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $_
shift() $_
Truth table0%0/3
A || B
A= shift()B= $_
ABresult
1X1
011
000
69 0 ▶ if ($arg =~ /<(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (\/)?)?\s*>.*<\/(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (\/)?)?\s*/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ m[<(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (/)?)?\s*>.*</(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (/)?)?\s*]) { } 0 0 0
70 0 return 1;
71 } else {
72 0 return 0;
73 }
74 0 ▶ $_ = $arg if ($arg);
Branch: 1 branch
BranchTrueFalseTotal
if $arg 0 0 0
75 0 ▶ $self->{string} = $arg if ($arg);
Branch: 1 branch
BranchTrueFalseTotal
if $arg 0 0 0
76 }
77  
78 ##
79 ## Private method that matches for opentagged.
80 ##
81  
82 0 ▶sub _is_open_tagged {
Subroutine _is_open_tagged: not called CC=5 SCAR=34.0
83 0 my $self = shift;
84 0 ▶ my $arg = shift || $_;
Condition0%0/3
shift() || $_
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $_
shift() $_
Truth table0%0/3
A || B
A= shift()B= $_
ABresult
1X1
011
000
85 0 ▶ if ($arg =~ /<(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (\/)?)?\s*>/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ m[<(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (/)?)?\s*>]) { } 0 0 0
86 0 return 1;
87 } else {
88 0 return 0;
89 }
90 0 ▶ $_ = $arg if ($arg);
Branch: 1 branch
BranchTrueFalseTotal
if $arg 0 0 0
91 0 ▶ $self->{string} = $arg if ($arg);
Branch: 1 branch
BranchTrueFalseTotal
if $arg 0 0 0
92 }
93  
94 ##
95 ## Private method that matches for closetagged.
96 ##
97  
98 0 ▶sub _is_close_tagged {
Subroutine _is_close_tagged: not called CC=5 SCAR=34.0
99 0 my $self = shift;
100 0 ▶ my $arg = shift || $_;
Condition0%0/3
shift() || $_
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $_
shift() $_
Truth table0%0/3
A || B
A= shift()B= $_
ABresult
1X1
011
000
101 0 ▶ if ($arg =~ /<\/([a-zA-Z])+\s*>/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ m[</([a-zA-Z])+\s*>]) { } 0 0 0
102 0 return 1;
103 } else {
104 0 return 0;
105 }
106 0 ▶ $_ = $arg if ($arg);
Branch: 1 branch
BranchTrueFalseTotal
if $arg 0 0 0
107 0 ▶ $self->{string} = $arg if ($arg);
Branch: 1 branch
BranchTrueFalseTotal
if $arg 0 0 0
108 }
109  
110 ##
111 ## Private method that matches for empty.
112 ##
113  
114 0 ▶sub _is_empty_element {
Subroutine _is_empty_element: not called CC=5 SCAR=34.0
115 0 my $self = shift;
116 0 ▶ my $arg = shift || $_;
Condition0%0/3
shift() || $_
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $_
shift() $_
Truth table0%0/3
A || B
A= shift()B= $_
ABresult
1X1
011
000
117 0 ▶ if ($arg =~ /<(([a-zA-Z])+((\s+\w+)=?("?.+"?)?){0,})(\s*\/)\s*>/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ m[<(([a-zA-Z])+((\s+\w+)=?("?.+"?)?){0,})(\s*/)\s*>]) { } 0 0 0
118 0 return 1;
119 } else {
120 0 return 0;
121 }
122 0 ▶ $_ = $arg if ($arg);
Branch: 1 branch
BranchTrueFalseTotal
if $arg 0 0 0
123 0 ▶ $self->{string} = $arg if ($arg);
Branch: 1 branch
BranchTrueFalseTotal
if $arg 0 0 0
124 }
125  
126 ##
127 ## Private method for comment().
128 ##
129  
130 0 ▶sub _is_comment {
Subroutine _is_comment: not called CC=7 SCAR=40.3
131 0 my $self = shift;
132 0 ▶ my $arg = shift || $_;
Condition0%0/3
shift() || $_
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $_
shift() $_
Truth table0%0/3
A || B
A= shift()B= $_
ABresult
1X1
011
000
133
134 0 ▶ if ($Allow_Hyphen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HTML::TagUtil::Allow_Hyphen) { } 0 0 0
135 0 ▶ if ($arg =~ /<!--.*-->/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /<!--.*-->/) { } 0 0 0
136 0 return 1;
137 } else {
138 0 return 0;
139 }
140 } else {
141 0 ▶ if ($arg =~ /<!--[^\-]-->/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /<!--[^\-]-->/) { } 0 0 0
142 0 return 1;
143 } else {
144 0 return 0;
145 }
146 }
147 0 ▶ $_ = $arg if ($arg);
Branch: 1 branch
BranchTrueFalseTotal
if $arg 0 0 0
148 0 ▶ $self->{string} = $arg if ($arg);
Branch: 1 branch
BranchTrueFalseTotal
if $arg 0 0 0
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 0 ▶sub string {
Subroutine string: not called CC=3 SCAR=24.8
Pod undocumented
162 0 my $self = shift;
163 0 my $string = $self->{string};
164 0 ▶ $string = shift unless ($self->{string});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"string"} 0 0 0
165 0 ▶ return $self->{string} unless ($string);
Branch: 1 branch
BranchTrueFalseTotal
unless $string 0 0 0
166 }
167  
168 0 ▶sub allow_hyphen {
Subroutine allow_hyphen: not called CC=2 SCAR=17.9
Pod undocumented
169 0 my $self = shift;
170 0 my $arg = shift;
171 0 $Allow_Hyphen = $arg;
172 0 ▶ return $Allow_Hyphen unless ($arg);
Branch: 1 branch
BranchTrueFalseTotal
unless $arg 0 0 0
173 }
174  
175 0 ▶sub tagged {
Subroutine tagged: not called CC=6 SCAR=37.4
Pod documented
176 0 my $self = shift;
177 0 ▶ my $string = shift || $self->{string} || $_; #string to look at.
Condition0%0/6
shift() || $self->{'string'} || $_
l!l&&r!l&&!r
000
shift() or $self->{"string"}
l!l&&r!l&&!r
000
MC/DC0%0/3
shift() || $self->{'string'} || $_
shift() $self->{"string"} $_
Truth table0%0/4
A or B || C
A= shift()B= $self->{"string"}C= $_
ABCresult
1XX1
01X1
0011
0000
178 ##check to see if it has both a start tag and an end tag.
179 0 ▶ if (_is_fully_tagged ($self->{string})) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_fully_tagged($self->{'string'})) { } 0 0 0
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 ▶ $self->{string} = $string if ($string);
Branch: 1 branch
BranchTrueFalseTotal
if $string 0 0 0
191 0 ▶ $_ = $self->{string} if ($self->{string});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"string"} 0 0 0
192 }
193  
194 0 ▶sub opentagged {
Subroutine opentagged: not called CC=6 SCAR=37.4
Pod documented
195 0 my $self = shift;
196 0 ▶ my $string = shift || $self->{string} || $_; #string to look at.
Condition0%0/6
shift() || $self->{'string'} || $_
l!l&&r!l&&!r
000
shift() or $self->{"string"}
l!l&&r!l&&!r
000
MC/DC0%0/3
shift() || $self->{'string'} || $_
shift() $self->{"string"} $_
Truth table0%0/4
A or B || C
A= shift()B= $self->{"string"}C= $_
ABCresult
1XX1
01X1
0011
0000
197 ##check to see if it at least has a start tag.
198 0 ▶ if (_is_open_tagged ($string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_open_tagged($string)) { } 0 0 0
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 ▶ $self->{string} = $string if ($string);
Branch: 1 branch
BranchTrueFalseTotal
if $string 0 0 0
210 0 ▶ $_ = $self->{string} if ($self->{string});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"string"} 0 0 0
211 }
212  
213 0 ▶sub closetagged {
Subroutine closetagged: not called CC=6 SCAR=37.4
Pod documented
214 0 my $self = shift;
215 0 ▶ my $string = shift || $self->{string} || $_; #string to look at.
Condition0%0/6
shift() || $self->{'string'} || $_
l!l&&r!l&&!r
000
shift() or $self->{"string"}
l!l&&r!l&&!r
000
MC/DC0%0/3
shift() || $self->{'string'} || $_
shift() $self->{"string"} $_
Truth table0%0/4
A or B || C
A= shift()B= $self->{"string"}C= $_
ABCresult
1XX1
01X1
0011
0000
216 ##check to see if it at least has an end tag.
217 0 ▶ if (_is_close_tagged ($string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_close_tagged($string)) { } 0 0 0
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 ▶ $self->{string} = $string if ($string);
Branch: 1 branch
BranchTrueFalseTotal
if $string 0 0 0
229 0 ▶ $_ = $self->{string} if ($self->{string});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"string"} 0 0 0
230 }
231  
232 0 ▶sub tagpos {
Subroutine tagpos: not called CC=11 SCAR=48.8
Pod documented
233 0 my $self = shift;
234 0 ▶ my $string = shift || $self->{string} || $_; #string to look at.
Condition0%0/6
shift() || $self->{'string'} || $_
l!l&&r!l&&!r
000
shift() or $self->{"string"}
l!l&&r!l&&!r
000
MC/DC0%0/3
shift() || $self->{'string'} || $_
shift() $self->{"string"} $_
Truth table0%0/4
A or B || C
A= shift()B= $self->{"string"}C= $_
ABCresult
1XX1
01X1
0011
0000
235 0 ▶ my $tag = shift || $self->{tag} || $_; #tag to look for.
Condition0%0/6
shift() || $self->{'tag'} || $_
l!l&&r!l&&!r
000
shift() or $self->{"tag"}
l!l&&r!l&&!r
000
MC/DC0%0/3
shift() || $self->{'tag'} || $_
shift() $self->{"tag"} $_
Truth table0%0/4
A or B || C
A= shift()B= $self->{"tag"}C= $_
ABCresult
1XX1
01X1
0011
0000
236 0 ▶ my $offset = shift || 0; # offset.
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
237 0 ▶ $tag = '<' . $tag . '>' if ($tag !~ /(<(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (\/)?)?\s*>|<\/([a-zA-Z])+\s*>)/);
Branch: 1 branch
BranchTrueFalseTotal
unless $tag =~ m[(<(([a-zA-Z])+((\s+\w+)=?("?\w+"?)?){0,})( (/)?)?\s*>|</([a-zA-Z])+\s*>)] 0 0 0
238 0 return index ($string, $tag, $offset) + 1;
239 0 ▶ $self->{string} = $string if ($string);
Branch: 1 branch
BranchTrueFalseTotal
if $string 0 0 0
240 0 ▶ $self->{tag } = $tag if ($tag);
Branch: 1 branch
BranchTrueFalseTotal
if $tag 0 0 0
241 0 ▶ $_ = $self->{string} if ($self->{string});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"string"} 0 0 0
242 0 ▶ $_ .= "||$tag" if ($self->{tag});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tag"} 0 0 0
243 }
244  
245 0 ▶sub empty {
Subroutine empty: not called CC=6 SCAR=37.4
Pod documented
246 0 my $self = shift;
247 0 ▶ my $string = shift || $self->{string} || $_;
Condition0%0/6
shift() || $self->{'string'} || $_
l!l&&r!l&&!r
000
shift() or $self->{"string"}
l!l&&r!l&&!r
000
MC/DC0%0/3
shift() || $self->{'string'} || $_
shift() $self->{"string"} $_
Truth table0%0/4
A or B || C
A= shift()B= $self->{"string"}C= $_
ABCresult
1XX1
01X1
0011
0000
248 0 ▶ if (_is_empty_element ($string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_empty_element($string)) { } 0 0 0
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 ▶ $self->{string} = $string if ($string);
Branch: 1 branch
BranchTrueFalseTotal
if $string 0 0 0
259 0 ▶ $_ = $self->{string} if ($self->{string});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"string"} 0 0 0
260 }
261  
262 0 ▶sub comment {
Subroutine comment: not called CC=6 SCAR=37.4
Pod documented
263 0 my $self = shift;
264 0 ▶ my $string = shift || $self->{string} || $_;
Condition0%0/6
shift() || $self->{'string'} || $_
l!l&&r!l&&!r
000
shift() or $self->{"string"}
l!l&&r!l&&!r
000
MC/DC0%0/3
shift() || $self->{'string'} || $_
shift() $self->{"string"} $_
Truth table0%0/4
A or B || C
A= shift()B= $self->{"string"}C= $_
ABCresult
1XX1
01X1
0011
0000
265 0 ▶ if (_is_comment($string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_comment($string)) { } 0 0 0
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 ▶ $self->{string} = $string if ($string);
Branch: 1 branch
BranchTrueFalseTotal
if $string 0 0 0
276 0 ▶ $_ = $self->{string} if ($self->{string});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"string"} 0 0 0
277 }
278  
279  
280  
281 1 1;
282  
283 __END__
↑ Summary