Util.pm

filter: Statementstmt 74.3% 350 / 471 Branchbran 56.4% 166 / 294 Conditioncond 40.3% 23 / 57 MC/DCmcdc 21.6% 8 / 37 Subroutinesub 76.1% 64 / 84 Podpod 0.0% 0 / 27 totaltotal 62.9% 611 / 970 CC 171 SCAR 32.5
CC
171
Cov
66%
textURL
182.0
createListSequence
52.6
_url_parse
51.0
CRAP 25.7
↑ Summary Parser.pm »
1 # $Id: Util.pm 284 2006-12-01 07:51:49Z chronos $
2 package BBCode::Util;
3 7 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use HTML::Entities ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 our $VERSION = '0.34';
12 7 our @EXPORT;
13 7 our @EXPORT_OK;
14 7 our %EXPORT_TAGS;
15  
16 189 ▶sub _export {
Subroutine _export: called CC=3 SCAR=11.0
17 189 my $sym = shift;
18 189 $sym =~ s/^(?=\w)/&/;
19 189 unshift @_, 'ALL';
20 189 ▶ while(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 371 189 560
21 371 my $tag = shift;
22 371 ▶ $EXPORT_TAGS{$tag} = [] unless exists $EXPORT_TAGS{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $BBCode::Util::EXPORT_TAGS{$tag} 49 322 371
23 371 push @{$EXPORT_TAGS{$tag}}, $sym;
24 }
25 }
26  
27 7 ▶BEGIN { _export qw(pkgFilename pkg) }
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2135 ▶sub pkgFilename($) {
Subroutine pkgFilename: called CC=2 SCAR=7.2
Pod undocumented
29 2135 ▶ if($_[0] =~ /^((?:\w+::)*\w+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^((?:\w+::)*\w+)$/) 2135 0 2135
30 2135 local $_ = $1;
31 2135 s#::#/#g;
32 2135 s/$/.pm/;
33 2135 return $_;
34 }
35 0 return undef;
36 }
37  
38 7 my %userTags = (
39 'BODY' => 'BBCode::Body',
40 );
41  
42 7 ▶BEGIN { _export qw(tagUserDefined tag) }
Subroutine BEGIN: called CC=1 SCAR=0.0
43 0 ▶sub tagUserDefined($) {
Subroutine tagUserDefined: not called CC=3 SCAR=24.8
Pod undocumented
44 0 my $pkg = shift;
45 0 my $file = pkgFilename($pkg);
46 0 ▶ croak qq(Invalid package name "$pkg") unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 0 0
47 0 require $file;
48 0 my $obj = bless {}, $pkg;
49 0 ▶ croak qq(Package "$pkg" does not inherit from BBCode::Tag) unless UNIVERSAL::isa($obj,'BBCode::Tag');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($obj, "BBCode::Tag") 0 0 0
50 0 $userTags{uc($obj->Tag)} = $pkg;
51 }
52  
53 7 ▶BEGIN { _export qw(tagLoadPackage tag) }
Subroutine BEGIN: called CC=1 SCAR=0.0
54 2133 ▶sub tagLoadPackage($) {
Subroutine tagLoadPackage: called CC=3 SCAR=11.0
Pod undocumented
55 2133 my($tag,$pkg);
56 2133 ▶ croak qq(Invalid tag name "$_[0]") unless $_[0] =~ m#^/?(_?\w+)$#;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ m[^/?(_?\w+)$] 0 2133 2133
57 2133 $tag = uc($1);
58 2133 ▶ if(exists $userTags{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $userTags{$tag}) { } 305 1828 2133
59 305 $pkg = $userTags{$tag};
60 } else {
61 1828 $tag =~ s/^_/x/;
62 1828 $pkg = "BBCode::Tag::$tag";
63 }
64 2133 my $file = pkgFilename($pkg);
65 2133 require $file;
66 2133 return $pkg;
67 }
68  
69 7 ▶BEGIN { _export qw(tagExists tag) }
Subroutine BEGIN: called CC=1 SCAR=0.0
70 154 ▶sub tagExists($) {
Subroutine tagExists: called CC=2 SCAR=7.4
Pod undocumented
71 154 my $tag = shift;
72 154 ▶ return 1 if eval {
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { &tagLoadPackage($tag); 1 } } 154 0 154
73 154 tagLoadPackage($tag);
74 154 1;
75 };
76 0 return 0;
77 }
78  
79 7 ▶BEGIN { _export qw(tagCanonical tag) }
Subroutine BEGIN: called CC=1 SCAR=0.0
80 3482 ▶sub tagCanonical($) {
Subroutine tagCanonical: called CC=4 SCAR=14.0
Pod undocumented
81 3482 local $_ = shift;
82 3482 ▶ if(ref $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 199 3283 3482
83 199 ▶ return $_->Tag if UNIVERSAL::isa($_,'BBCode::Tag');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_, "BBCode::Tag") 199 0 199
84 0 croak qq(Invalid reference);
85 } else {
86 3283 ▶ return uc($1) if /^(:\w+)$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^(:\w+)$/ 1982 1301 3283
87 1301 my $pkg = tagLoadPackage($_);
88 1301 return $pkg->Tag;
89 }
90 }
91  
92 7 ▶BEGIN { _export qw(tagObject tag) }
Subroutine BEGIN: called CC=1 SCAR=0.0
93 0 ▶sub tagObject($) {
Subroutine tagObject: not called CC=3 SCAR=24.8
Pod undocumented
94 0 my $tag = shift;
95 0 ▶ if(ref $tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tag) { } 0 0 0
96 0 ▶ return $tag if UNIVERSAL::isa($tag,'BBCode::Tag');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($tag, "BBCode::Tag") 0 0 0
97 0 croak qq(Invalid reference);
98 } else {
99 0 my $pkg = tagLoadPackage($tag);
100 0 return bless {}, $pkg;
101 }
102 }
103  
104 7 ▶BEGIN { _export qw(tagHierarchy tag) }
Subroutine BEGIN: called CC=1 SCAR=0.0
105 469 ▶sub tagHierarchy($) {
Subroutine tagHierarchy: called CC=2 SCAR=7.0
Pod undocumented
106 469 my $tag = tagCanonical(shift);
107 469 ▶ return $tag if $tag =~ /^:/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^:/ 0 469 469
108 469 my $pkg = tagLoadPackage($tag);
109 469 return ($pkg->Tag, map { ":$_" } ($pkg->Class, 'ALL'));
110 }
111  
112 7 ▶BEGIN { _export qw(quoteQ quote) }
Subroutine BEGIN: called CC=1 SCAR=0.0
113 59 ▶sub quoteQ($) {
Subroutine quoteQ: called CC=1 SCAR=0.0
Pod undocumented
114 59 local $_ = $_[0];
115 59 s/([\\'])/\\$1/g;
116 59 return qq('$_');
117 }
118  
119 7 ▶BEGIN { _export qw(quoteQQ quote) }
Subroutine BEGIN: called CC=1 SCAR=0.0
120 59 ▶sub quoteQQ($) {
Subroutine quoteQQ: called CC=1 SCAR=0.0
Pod undocumented
121 59 local $_ = $_[0];
122 59 s/([\\"])/\\$1/g;
123 59 return qq("$_");
124 }
125  
126 7 ▶BEGIN { _export qw(quoteBS quote) }
Subroutine BEGIN: called CC=1 SCAR=0.0
127 59 ▶sub quoteBS($) {
Subroutine quoteBS: called CC=1 SCAR=0.0
Pod undocumented
128 59 local $_ = $_[0];
129 59 s/([\\\[\]"'=,\s\n])/\\$1/g;
130 59 return $_;
131 }
132  
133 7 ▶BEGIN { _export qw(quoteRaw quote) }
Subroutine BEGIN: called CC=1 SCAR=0.0
134 59 ▶sub quoteRaw($) {
Subroutine quoteRaw: called CC=2 SCAR=6.9
Pod undocumented
135 59 local $_ = $_[0];
136 59 ▶ return undef if /[\\\[\]"'=,\s\n]/;
Branch: 1 branch
BranchTrueFalseTotal
if /[\\\[\]"'=,\s\n]/ 10 49 59
137 49 return $_;
138 }
139  
140 7 ▶BEGIN { _export qw(quote quote) }
Subroutine BEGIN: called CC=1 SCAR=0.0
141 54 ▶sub quote($) {
Subroutine quote: called CC=2 SCAR=6.9
Pod undocumented
142 my @q = sort {
143 207 ▶ (length($a) <=> length($b)) or ($a cmp $b)
Condition100%3/3
length $a <=> length $b || $a cmp $b
l!l&&r!l&&!r
1025847
MC/DC100%2/2
length $a <=> length $b || $a cmp $b
length $a <=> length $b $a cmp $b
Truth table100%3/3
A || B
A= length $a <=> length $bB= $a cmp $b
ABresult
1X1
011
000
144 } grep {
145 54 defined $_
146 } (quoteQ $_[0], quoteQQ $_[0], quoteBS $_[0], quoteRaw $_[0]);
147 54 return $q[0];
148 }
149  
150 7 ▶BEGIN { _export qw(encodeHTML encode); }
Subroutine BEGIN: called CC=1 SCAR=0.0
151 122 ▶sub encodeHTML($) {
Subroutine encodeHTML: called CC=2 SCAR=7.0
Pod undocumented
152 122 local $_ = $_[0];
153 122 ▶ if(defined $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) 122 0 122
154 # Basic HTML/XML escapes
155 122 s/&/&amp;/g;
156 122 s/</&lt;/g;
157 122 s/>/&gt;/g;
158 122 s/"/&quot;/g;
159 # &apos; is XML-only
160 122 s/'/&#39;/g;
161 }
162 122 return $_;
163 }
164  
165 7 ▶BEGIN { _export qw(decodeHTML encode); }
Subroutine BEGIN: called CC=1 SCAR=0.0
166 0 ▶sub decodeHTML($) {
Subroutine decodeHTML: not called CC=1 SCAR=6.9
Pod undocumented
167 0 return HTML::Entities::decode($_[0]);
168 }
169  
170 7 ▶BEGIN { _export qw(parseBool parse) }
Subroutine BEGIN: called CC=1 SCAR=0.0
171 17 ▶sub parseBool($) {
Subroutine parseBool: called CC=7 SCAR=23.7
Pod undocumented
172 17 local $_ = $_[0];
173 17 ▶ return undef if not defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 17 17
174 17 ▶ return $_->as_bool() if ref $_ and UNIVERSAL::can($_, 'as_bool');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ and UNIVERSAL::can($_, "as_bool") 0 17 17
Condition33%1/3
ref $_ and UNIVERSAL::can($_, "as_bool")
!ll&&!rl&&r
1700
MC/DC0%0/2
ref $_ and UNIVERSAL::can($_, "as_bool")
ref $_ UNIVERSAL::can($_, "as_bool")
Truth table33%1/3
A and B
A= ref $_B= UNIVERSAL::can($_, "as_bool")
ABresult
0X0
100
111
175 17 ▶ return 1 if /^(?:
Branch: 1 branch
BranchTrueFalseTotal
if /^(?: 1 | T | TR | TRU | TRUE | Y | YE | YES | ON )$/xi 13 4 17
176 1 |
177 T | TR | TRU | TRUE |
178 Y | YE | YES |
179 ON
180 )$/ix;
181 4 ▶ return 0 if /^(?:
Branch: 1 branch
BranchTrueFalseTotal
if /^(?: 0 | F | FA | FAL | FALS | FALSE | N | NO | OFF )$/xi 4 0 4
182 0 |
183 F | FA | FAL | FALS | FALSE |
184 N | NO |
185 OFF
186 )$/ix;
187 0 ▶ return $_ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
188 }
189  
190 7 ▶BEGIN { _export qw(parseInt parse) }
Subroutine BEGIN: called CC=1 SCAR=0.0
191 53 ▶sub parseInt($) {
Subroutine parseInt: called CC=4 SCAR=13.9
Pod undocumented
192 53 my $num = shift;
193 53 ▶ return undef if not defined $num;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 0 53 53
194 53 $num =~ s/[\s,_]+//g;
195 53 $num =~ s/^\+//;
196 53 ▶ return 0 if $num =~ /^-?$/;
Branch: 1 branch
BranchTrueFalseTotal
if $num =~ /^-?$/ 6 47 53
197 47 ▶ return 0+$1 if $num =~ /^ ( -? \d+ ) $/x;
Branch: 1 branch
BranchTrueFalseTotal
if $num =~ /^ ( -? \d+ ) $/x 46 1 47
198 1 return undef;
199 }
200  
201 7 ▶BEGIN { _export qw(parseNum parse) }
Subroutine BEGIN: called CC=1 SCAR=0.0
202 sub parseNum($);
203 48 ▶sub parseNum($) {
Subroutine parseNum: called CC=8 SCAR=21.5
Pod undocumented
204 48 my $num = shift;
205 48 ▶ return undef if not defined $num;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 0 48 48
206 48 $num =~ s/[\s,_]+//g;
207 48 ▶ if($num =~ /^ (.*) e (.*) $/ix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num =~ /^ (.*) e (.*) $/xi) 4 44 48
208 4 my($m,$e) = ($1,$2);
209 4 $m = parseNum $m;
210 4 $e = parseNum $e;
211 4 ▶ return $m * (10 ** $e) if defined $m and defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $m and defined $e 4 0 4
Condition33%1/3
defined $m and defined $e
!ll&&!rl&&r
004
MC/DC0%0/2
defined $m and defined $e
defined $m defined $e
Truth table33%1/3
A and B
A= defined $mB= defined $e
ABresult
0X0
100
111
212 0 return undef;
213 }
214 44 ▶ if($num =~ /^ ([^.]*) \. ([^.]*) $/x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num =~ /^ ([^.]*) \. ([^.]*) $/x) 13 31 44
215 13 my($i,$f) = ($1,$2);
216 13 $i = parseInt $i;
217 13 ▶ return undef unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 13 13
218 13 ▶ return undef unless $f =~ /^(\d*)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $f =~ /^(\d*)$/ 0 13 13
219 13 $num = "$i.$f";
220 13 $num =~ s/\.$//;
221 13 return 0+$num;
222 }
223 31 return parseInt($num);
224 }
225  
226 7 ▶BEGIN { _export qw(parseEntity parse) }
Subroutine BEGIN: called CC=1 SCAR=0.0
227 sub parseEntity($);
228 15 ▶sub parseEntity($) {
Subroutine parseEntity: called CC=9 SCAR=22.0
Pod undocumented
229 15 local $_ = $_[0];
230 15 ▶ return undef unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 15 15
231 15 s/^&(.*);$/$1/;
232 15 s/^#([xob])/0$1/i;
233 15 s/^#//;
234 15 s/^U\+/0x/;
235  
236 15 my $ch;
237 15 ▶ if(/^ 0x ([0-9A-F]+) $/xi) {
Branch: 5 branches
BranchTrueFalseTotal
if (/^ 0x ([0-9A-F]+) $/xi) { } 3 12 15
elsif (/^ 0o ([0-7]+) $/xi) { } 1 11 12
elsif (/^ 0b ([01]+) $/xi) { } 1 10 11
elsif (/^ 0 ([0-7]{3}) $/x) { } 0 10 10
elsif (/^ (\d+) $/x) { } 1 9 10
238 3 $ch = hex($1);
239 } elsif(/^ 0o ([0-7]+) $/xi) {
240 1 $ch = oct($1);
241 } elsif(/^ 0b ([01]+) $/xi) {
242 1 my $b = ("\0" x 4) . pack("B*", $1);
243 1 $ch = unpack "N", substr($b, -4);
244 } elsif(/^ 0 ([0-7]{3}) $/x) {
245 0 $ch = oct($1);
246 } elsif(/^ (\d+) $/x) {
247 1 $ch = 0+$1;
248 }
249 15 ▶ return sprintf "#x%X", $ch if defined $ch;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ch 6 9 15
250  
251 9 my $decoded = HTML::Entities::decode("&$_;");
252 9 ▶ return undef if $decoded eq "&$_;";
Branch: 1 branch
BranchTrueFalseTotal
if $decoded eq "&$_;" 1 8 9
253 8 return $_;
254 }
255  
256 7 ▶BEGIN { _export qw(parseListType parse) }
Subroutine BEGIN: called CC=1 SCAR=0.0
257 7 my %listtype = (
258 '*' => [ qw(ul) ],
259 '1' => [ qw(ol decimal) ],
260 '01' => [ qw(ol decimal-leading-zero) ],
261 'A' => [ qw(ol upper-latin) ],
262 'a' => [ qw(ol lower-latin) ],
263 'I' => [ qw(ol upper-roman) ],
264 'i' => [ qw(ol lower-roman) ],
265 "\x{3B1}" => [ qw(ol lower-greek) ],
266 "\x{5D0}" => [ qw(ol hebrew) ],
267 "\x{3042}" => [ qw(ol hiragana) ],
268 "\x{3044}" => [ qw(ol hiragana-iroha) ],
269 "\x{30A2}" => [ qw(ol katakana) ],
270 "\x{30A4}" => [ qw(ol katakana-iroha) ],
271 );
272 9 ▶sub parseListType($) {
Subroutine parseListType: called CC=5 SCAR=17.3
Pod undocumented
273 9 local $_ = $_[0];
274 9 my @ret;
275 9 ▶ if(defined $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) 1 8 9
276 1 ▶ if(/^(disc|circle|square|none)$/i) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^(disc|circle|square|none)$/i) { } 0 1 1
elsif (/^( decimal(?:-leading-zero)? | (?:upper|lower)-(?:roman|latin|alpha) | lower-greek | hebrew | georgian | armenian | cjk-ideographic | (?:hiragana|katakana)(?:-iroha)? )$/xi) { } 0 1 1
elsif (exists $listtype{$_}) { } 1 0 1
277 0 @ret = ('ul', lc $1);
278 } elsif(/^(
279 decimal(?:-leading-zero)? |
280 (?:upper|lower)-(?:roman|latin|alpha) |
281 lower-greek |
282 hebrew |
283 georgian |
284 armenian |
285 cjk-ideographic |
286 (?:hiragana|katakana)(?:-iroha)?
287 )$/ix) {
288 0 @ret = ('ol', lc $1);
289 } elsif(exists $listtype{$_}) {
290 1 @ret = @{$listtype{$_}};
291 }
292 }
293 9 return @ret;
294 }
295  
296 # Conversion factors from CSS units to points
297 7 my %conv = (
298 # Integer conversions within English units
299 pt => 1,
300 pc => 12,
301 in => 72,
302  
303 # Floating-point conversions from Metric units
304 mm => 72/25.4,
305 cm => 72/2.54,
306  
307 # Somewhat approximate, but the CSS standard is actually rather
308 # picky about how many pixels a 'pixel' is at different resolutions,
309 # so this is actually relatively reliable.
310 px => 0.75,
311 );
312  
313 # Emulation of <font size="num">...</font> from HTML 3.2
314 # See <URL:http://www.w3.org/TR/CSS21/fonts.html#font-size-props>
315 # Tweaked slightly to be more logical
316 7 my @compat = qw(xx-small x-small small medium large x-large xx-large 300%);
317  
318 7 ▶BEGIN { _export qw(parseFontSize parse) }
Subroutine BEGIN: called CC=1 SCAR=0.0
319 sub parseFontSize($;$$$);
320 45 ▶sub parseFontSize($;$$$) {
Subroutine parseFontSize: called CC=29 SCAR=34.8
Pod undocumented
321 45 local $_ = shift;
322 45 ▶ return undef unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 45 45
323 45 my($base,$lo,$hi) = @_;
324 45 ▶ $base = 12 if not defined $base;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base 41 4 45
325 45 ▶ $lo = 8 if not defined $lo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lo 41 4 45
326 45 ▶ $hi = 72 if not defined $hi;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hi 41 4 45
327 45 s/\s+/ /g;
328 45 s/^\s|\s$//g;
329  
330 # CSS 2.1 15.7 <absolute-size>
331 45 ▶ if(/^( (?:xx?-)? (?:large|small) | medium )$/ix) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^( (?:xx?-)? (?:large|small) | medium )$/xi) 3 42 45
332 3 return lc $1;
333 }
334  
335 # CSS 2.1 15.7 <relative-size>
336 # Note: Since [FONT] is nestable and not readily computable before HTML
337 # rendering, this can allow a malicious user to escape the
338 # admin-defined font size limits
339 42 ▶ if(/^ ( larger | smaller ) $/ix) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^ ( larger | smaller ) $/xi) 2 40 42
340 2 return lc $1;
341 }
342  
343 # CSS 2.1 4.3.2 <length>
344 40 ▶ if(/^ ( [\s\d._+-]+ ) ( [a-z]+ ) $/ix) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^ ( [\s\d._+-]+ ) ( [a-z]+ ) $/xi) 17 23 40
345 17 my($n,$unit) = ($1,lc $2);
346 17 $n = parseNum $n;
347 17 ▶ if(defined $n and $n > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n and $n > 0) { } 17 0 17
Condition33%1/3
defined $n and $n > 0
!ll&&!rl&&r
0017
MC/DC0%0/2
defined $n and $n > 0
defined $n $n > 0
Truth table33%1/3
A and B
A= defined $nB= $n > 0
ABresult
0X0
100
111
348 17 my $conv;
349 17 ▶ if(exists $conv{$unit}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $conv{$unit}) { } 15 2 17
elsif ($unit =~ /^em$/i) { } 1 1 2
elsif ($unit =~ /^ex$/i) { } 1 0 1
350 15 $conv = $conv{$unit};
351 } elsif($unit =~ /^em$/i) {
352 1 $conv = $base;
353 } elsif($unit =~ /^ex$/i) {
354 1 $conv = $base * 0.5;
355 } else {
356 0 return undef;
357 }
358 17 my $n2 = $n * $conv;
359 17 ▶ if(defined $lo and $n2 < $lo) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $lo and $n2 < $lo) { } 2 15 17
elsif (defined $hi and $n2 > $hi) { } 3 12 15
Condition66%2/3
defined $lo and $n2 < $lo
!ll&&!rl&&r
0152
MC/DC50%1/2
defined $lo and $n2 < $lo
defined $lo $n2 < $lo
Truth table66%2/3
A and B
A= defined $loB= $n2 < $lo
ABresult
0X0
100
111
360 2 $n = $lo / $conv;
361 ▶ } elsif(defined $hi and $n2 > $hi) {
Condition66%2/3
defined $hi and $n2 > $hi
!ll&&!rl&&r
0123
MC/DC50%1/2
defined $hi and $n2 > $hi
defined $hi $n2 > $hi
Truth table66%2/3
A and B
A= defined $hiB= $n2 > $hi
ABresult
0X0
100
111
362 3 $n = $hi / $conv;
363 }
364 17 $n = sprintf "%.3f", $n;
365 17 $n =~ s/0+$//;
366 17 $n =~ s/\.$//;
367 17 return "$n$unit";
368 } else {
369 0 return undef;
370 }
371 }
372  
373 # CSS 2.1 4.3.3 <percentage>
374 # Note: The same concerns apply as for <relative-size>
375 23 ▶ if(/^ ( [\s\d._+-]+ ) % $/x) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^ ( [\s\d._+-]+ ) % $/x) 9 14 23
376 9 my $n = parseNum $1;
377 9 ▶ if(defined $n and $n > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n and $n > 0) { } 9 0 9
Condition33%1/3
defined $n and $n > 0
!ll&&!rl&&r
009
MC/DC0%0/2
defined $n and $n > 0
defined $n $n > 0
Truth table33%1/3
A and B
A= defined $nB= $n > 0
ABresult
0X0
100
111
378 9 $n *= 0.01;
379 9 my $n2 = $n * $base;
380 9 ▶ if(defined $lo and $n2 < $lo) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $lo and $n2 < $lo) { } 1 8 9
elsif (defined $hi and $n2 > $hi) { } 1 7 8
Condition66%2/3
defined $lo and $n2 < $lo
!ll&&!rl&&r
081
MC/DC50%1/2
defined $lo and $n2 < $lo
defined $lo $n2 < $lo
Truth table66%2/3
A and B
A= defined $loB= $n2 < $lo
ABresult
0X0
100
111
381 1 $n = $lo / $base;
382 ▶ } elsif(defined $hi and $n2 > $hi) {
Condition66%2/3
defined $hi and $n2 > $hi
!ll&&!rl&&r
071
MC/DC50%1/2
defined $hi and $n2 > $hi
defined $hi $n2 > $hi
Truth table66%2/3
A and B
A= defined $hiB= $n2 > $hi
ABresult
0X0
100
111
383 1 $n = $hi / $base;
384 }
385 9 $n *= 100;
386 9 $n = sprintf "%.3f", $n;
387 9 $n =~ s/0+$//;
388 9 $n =~ s/\.$//;
389 9 return "$n%";
390 } else {
391 0 return undef;
392 }
393 }
394  
395 # HTML 3.2 <font size="number">
396 # See <URL:http://www.w3.org/TR/REC-html32#font>
397 14 ▶ if(/^ (\d+) $/x) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^ (\d+) $/x) 8 6 14
398 8 my $n = 0+$1;
399 8 ▶ if($n >= 0 and $n < @compat) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n >= 0 and $n < @compat) { } 8 0 8
Condition33%1/3
$n >= 0 and $n < @compat
!ll&&!rl&&r
008
MC/DC0%0/2
$n >= 0 and $n < @compat
$n >= 0 $n < @compat
Truth table33%1/3
A and B
A= $n >= 0B= $n < @compat
ABresult
0X0
100
111
400 8 return $compat[$n];
401 } else {
402 0 return parseFontSize("$n pt",$base,$lo,$hi);
403 }
404 }
405  
406 # HTML 3.2 <font size="+number">
407 6 ▶ if(/^ \+ (\d+) $/x) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^ \+ (\d+) $/x) 2 4 6
408 # "+1" is roughly equivalent to CSS 2.1 "larger"
409 2 my $n = sprintf "%f%%", 100 * (1.25 ** $1);
410 2 return parseFontSize($n,$base,$lo,$hi);
411 }
412  
413 # HTML 3.2 <font size="-number">
414 4 ▶ if(/^ - (\d+) $/x) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^ - (\d+) $/x) 2 2 4
415 # "-1" is roughly equivalent to CSS 2.1 "smaller"
416 2 my $n = sprintf "%f%%", 100 * (0.85 ** $1);
417 2 return parseFontSize($n,$base,$lo,$hi);
418 }
419  
420 2 return undef;
421 }
422  
423 # Official CSS 2.1 colors are passed through as-is
424 7 my %cssColor = map { $_ => 1 } qw(
425 maroon red orange yellow olive
426 purple fuchsia white lime green
427 navy blue aqua teal
428 black silver gray
429 );
430  
431 # Other named colors must map to an official named color or an #RRGGBB color
432 7 my %extraColor = (
433 darkred => 'maroon',
434 darkblue => 'navy',
435 );
436  
437 7 ▶BEGIN { _export qw(parseColor parse) }
Subroutine BEGIN: called CC=1 SCAR=0.0
438 8 ▶sub parseColor($) {
Subroutine parseColor: called CC=12 SCAR=25.5
Pod undocumented
439 8 local $_ = $_[0];
440 8 ▶ return undef unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 8 8
441 8 s/\s+//g;
442 8 $_ = lc $_;
443  
444 8 ▶ return $1 if /^(\w+)$/ and exists $cssColor{$1};
Branch: 1 branch
BranchTrueFalseTotal
if /^(\w+)$/ and exists $cssColor{$1} 5 3 8
Condition100%3/3
/^(\w+)$/ and exists $cssColor{$1}
!ll&&!rl&&r
215
MC/DC100%2/2
/^(\w+)$/ and exists $cssColor{$1}
/^(\w+)$/ exists $cssColor{$1}
Truth table100%3/3
A and B
A= /^(\w+)$/B= exists $cssColor{$1}
ABresult
0X0
100
111
445 3 ▶ return $extraColor{$_} if exists $extraColor{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $extraColor{$_} 0 3 3
446  
447 3 ▶ if(s/^#//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^#//) { } 1 2 3
448 1 s/^ ( [0-9a-f]{1,2} ) $/$1$1$1/x;
449 1 s/^ ([0-9a-f]) \1 ([0-9a-f]) \2 ([0-9a-f]) \3 $/$1$2$3/x;
450  
451 1 ▶ return "#$_" if /^ [0-9a-f]{3} $/x;
Branch: 1 branch
BranchTrueFalseTotal
if /^ [0-9a-f]{3} $/x 0 1 1
452 1 ▶ return "#$_" if /^ [0-9a-f]{6} $/x;
Branch: 1 branch
BranchTrueFalseTotal
if /^ [0-9a-f]{6} $/x 1 0 1
453 } else {
454 2 ▶ return $1 if /^( rgb \( (?: \d+ , ){2} \d+ \) )$/x;
Branch: 1 branch
BranchTrueFalseTotal
if /^( rgb \( (?: \d+ , ){2} \d+ \) )$/x 0 2 2
455 2 ▶ return $1 if /^( rgba\( (?: \d+ , ){3} \d+ \) )$/x;
Branch: 1 branch
BranchTrueFalseTotal
if /^( rgba\( (?: \d+ , ){3} \d+ \) )$/x 0 2 2
456 2 ▶ return $1 if /^( rgb \( (?: \d+% , ){2} \d+% \) )$/x;
Branch: 1 branch
BranchTrueFalseTotal
if /^( rgb \( (?: \d+% , ){2} \d+% \) )$/x 0 2 2
457 2 ▶ return $1 if /^( rgba\( (?: \d+% , ){3} \d+% \) )$/x;
Branch: 1 branch
BranchTrueFalseTotal
if /^( rgba\( (?: \d+% , ){3} \d+% \) )$/x 1 1 2
458 }
459 1 return undef;
460 }
461  
462 35 ▶sub _url_parse_opaque($) {
Subroutine _url_parse_opaque: called CC=4 SCAR=14.3
463 35 local $_ = $_[0];
464 35 my @ret = (undef) x 3;
465  
466 35 ▶ $ret[2] = $1 if s/(#.*)$//;
Branch: 1 branch
BranchTrueFalseTotal
if s/(#.*)$// 0 35 35
467 35 ▶ $ret[0] = lc $1 if s/^([\w+-]+)://;
Branch: 1 branch
BranchTrueFalseTotal
if s/^([\w+-]+):// 30 5 35
468 35 $ret[1] = $_;
469  
470 35 ▶ return @ret if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 35 0 35
471 0 return \@ret;
472 }
473  
474 25 ▶sub _url_parse_query($) {
Subroutine _url_parse_query: called CC=3 SCAR=11.2
475 25 local $_ = $_[0];
476 25 my @ret = (undef) x 2;
477  
478 25 ▶ $ret[1] = $1 if s/(\?.*)$//;
Branch: 1 branch
BranchTrueFalseTotal
if s/(\?.*)$// 1 24 25
479 25 $ret[0] = $_;
480  
481 25 ▶ return @ret if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 25 0 25
482 0 return \@ret;
483 }
484  
485 19 ▶sub _url_parse_path($) {
Subroutine _url_parse_path: called CC=6 SCAR=24.1
486 19 local $_ = $_[0];
487 19 my @ret = (undef) x 2;
488  
489 19 ▶ if(s#^//##) {
Branch: 2 branches
BranchTrueFalseTotal
if (s[^//][]) { } 19 0 19
elsif (m[^/]) { } 0 0 0
490 19 ▶ $ret[0] = $1 if s#^([^/]+)##;
Branch: 1 branch
BranchTrueFalseTotal
if s[^([^/]+)][] 19 0 19
491 19 s#^$#/#;
492 19 $ret[1] = $_;
493 } elsif(m#^/#) {
494 0 $ret[1] = $_;
495 } else {
496 0 ▶ return () if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
497 0 return undef;
498 }
499  
500 19 ▶ return @ret if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 19 0 19
501 0 return \@ret;
502 }
503  
504 19 ▶sub _url_parse_server($) {
Subroutine _url_parse_server: called CC=11 SCAR=29.7
505 19 local $_ = $_[0];
506 19 my($userpass,$hostport);
507  
508 19 ▶ if(/^ ([^@]*) \@ ([^@]*) $/x) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^ ([^\@]*) \@ ([^\@]*) $/x) { } 0 19 19
509 0 ($userpass,$hostport) = ($1,$2);
510 } else {
511 19 $hostport = $_;
512 }
513  
514 19 my @ret = (undef) x 4;
515  
516 19 $_ = $userpass;
517 19 ▶ if(defined $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) 0 19 19
518 0 ▶ if(/^ ([^:]*) : ([^:]*) $/x) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^ ([^:]*) : ([^:]*) $/x) { } 0 0 0
519 0 @ret[0,1] = ($1,$2);
520 } else {
521 0 $ret[0] = $_;
522 }
523 }
524  
525 19 $_ = $hostport;
526 19 ▶ if(s/:(\d+)$//) {
Branch: 2 branches
BranchTrueFalseTotal
if (s/:(\d+)$//) { } 0 19 19
elsif (s/:([\w+-]+)$//) { } 0 19 19
527 0 $ret[3] = $1;
528 } elsif(s/:([\w+-]+)$//) {
529 0 $ret[3] = getservbyname($1,'tcp');
530 0 ▶ goto Failure if not defined $ret[3];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret[3] 0 0 0
531 } else {
532 19 s/:$//;
533 }
534  
535 19 s/\.*$/./;
536 19 ▶ if(/^ ( (?: [\w-]+ \. )+ ) $/x) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^ ( (?: [\w-]+ \. )+ ) $/x) 15 4 19
537 15 $ret[2] = $1;
538 15 $ret[2] =~ s/\.$//;
539 }
540  
541 19 ▶ goto Failure if not defined $ret[2];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret[2] 4 15 19
542 15 ▶ return @ret if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 15 0 15
543 0 return \@ret;
544  
545 4 ▶Failure:
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 4 0 4
546 return () if wantarray;
547 0 return undef;
548 }
549  
550 7 my %urltype = (
551 'http' => 3,
552 'https' => 3,
553 'ftp' => 3,
554  
555 'file' => 2,
556  
557 'mailto' => 1,
558  
559 'data' => 0,
560 'javascript' => 0,
561 );
562  
563 35 ▶sub _url_parse($$) {
Subroutine _url_parse: called CC=31 SCAR=39.3
564 35 my($str,$schemes) = @_;
565  
566 35 my($scheme,$opaque,$fragment) = _url_parse_opaque($str);
567 35 ▶ return undef unless defined $scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scheme 5 30 35
568 30 ▶ return undef unless exists $urltype{$scheme};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $urltype{$scheme} 0 30 30
569  
570 30 ▶ if($urltype{$scheme} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($urltype{$scheme} > 0) 25 5 30
571 25 my($rest,$query) = _url_parse_query($opaque);
572  
573 25 ▶ if($urltype{$scheme} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($urltype{$scheme} > 1) 19 6 25
574 19 my($auth,$path) = _url_parse_path($rest);
575 19 ▶ return undef unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 19 19
576  
577 19 ▶ if($urltype{$scheme} > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($urltype{$scheme} > 2) 19 0 19
578 19 ▶ return undef unless defined $auth;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $auth 0 19 19
579 19 my($user,$pass,$host,$port) = _url_parse_server($auth);
580 19 ▶ return undef unless defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 4 15 19
581  
582 15 $auth = '';
583 15 ▶ if(defined $user) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $user) 0 15 15
584 0 $auth .= $user;
585 0 ▶ $auth .= ':'.$pass if defined $pass;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pass 0 0 0
586 0 $auth .= '@';
587 }
588 15 $auth .= $host;
589 15 ▶ $auth .= ':'.$port if defined $port;
Branch: 1 branch
BranchTrueFalseTotal
if defined $port 0 15 15
590 }
591  
592 15 ▶ $rest = join '', map { defined $_ ? $_ : '' } ('//',$auth,$path);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 45 0 45
593 }
594  
595 21 ▶ $opaque = join '', map { defined $_ ? $_ : '' } ($rest,$query);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 22 20 42
596 }
597 26 ▶ $str = $scheme.':'.$opaque.(defined $fragment ? $fragment : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $fragment ? : 0 26 26
598  
599 26 my $url = URI->new_abs($str, 'http://sanity.check.example.com/')->canonical;
600 26 ▶ return undef unless defined $url->scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url->scheme 0 26 26
601 26 ▶ return undef unless exists $$schemes{$url->scheme};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$schemes{$url->scheme} 4 22 26
602 22 ▶ return undef if $url->as_string =~ /\bsanity\.check\.example\.com\b/i;
Branch: 1 branch
BranchTrueFalseTotal
if $url->as_string =~ /\bsanity\.check\.example\.com\b/i 0 22 22
603 22 ▶ return undef if $url->can('userinfo') and defined $url->userinfo;
Branch: 1 branch
BranchTrueFalseTotal
if $url->can("userinfo") and defined $url->userinfo 0 22 22
Condition66%2/3
$url->can("userinfo") and defined $url->userinfo
!ll&&!rl&&r
7150
MC/DC0%0/2
$url->can("userinfo") and defined $url->userinfo
$url->can("userinfo") defined $url->userinfo
Truth table66%2/3
A and B
A= $url->can("userinfo")B= defined $url->userinfo
ABresult
0X0
100
111
604 22 ▶ return undef if $url->can('host') and not defined $url->host;
Branch: 1 branch
BranchTrueFalseTotal
if $url->can("host") and not defined $url->host 0 22 22
Condition66%2/3
$url->can("host") and not defined $url->host
!ll&&!rl&&r
7150
MC/DC0%0/2
$url->can("host") and not defined $url->host
$url->can("host") not defined $url->host
Truth table66%2/3
A and not(B)
A= $url->can("host")B= not defined $url->host
ABresult
0X0
100
111
605 22 ▶ if($url->scheme eq 'mailto') {
Branch: 1 branch
BranchTrueFalseTotal
if ($url->scheme eq "mailto") 6 16 22
606 6 my %unsafe = $url->headers;
607 6 my %safe;
608 6 foreach my $key (keys %unsafe) {
609 6 ▶ if($key =~ /^(?:to|cc|bcc)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^(?:to|cc|bcc)$/i) 6 0 6
610 6 my @to = split /,/, $unsafe{$key};
611 6 $key = lc $key;
612 6 foreach(@to) {
613 6 ▶ if(/^ ( [\w.+-]+ \@ (?: \w[\w-]*(?<=\w) \. )+ [a-z]{2,6} ) $/xi) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^ ( [\w.+-]+ \@ (?: \w[\w-]*(?<=\w) \. )+ [a-z]{2,6} ) $/xi) 2 4 6
614 2 ▶ if(exists $safe{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $safe{$key}) { } 0 2 2
615 0 $safe{$key} .= ",$1";
616 } else {
617 2 $safe{$key} = $1;
618 }
619 }
620 }
621 6 next;
622 }
623 0 ▶ if($key =~ /^subject$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^subject$/i) 0 0 0
624 0 ▶ if($unsafe{$key} =~ /^ ( [\x20-\x7E]+ ) $/x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unsafe{$key} =~ /^ ( [\x20-\x7E]+ ) $/x) 0 0 0
625 0 $safe{subject} = $1;
626 }
627 0 next;
628 }
629 }
630 6 ▶ return undef unless exists $safe{to};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $safe{"to"} 4 2 6
631 2 $url->headers(%safe);
632 }
633 18 return $url;
634 }
635  
636 7 ▶BEGIN { _export qw(parseURL parse) }
Subroutine BEGIN: called CC=1 SCAR=0.0
637 7 my %schemes = map { $_ => 1 } qw(http https ftp mailto data);
638 20 ▶sub parseURL($) {
Subroutine parseURL: called CC=3 SCAR=11.0
Pod undocumented
639 20 foreach('%', 'http://%', 'mailto:%') {
640 32 my $str = $_;
641 32 $str =~ s/%/$_[0]/g;
642 32 my $url = _url_parse($str, \%schemes);
643 32 ▶ return $url if defined $url;
Branch: 1 branch
BranchTrueFalseTotal
if defined $url 16 16 32
644 }
645 4 return undef;
646 }
647  
648 7 ▶BEGIN { _export qw(parseMailURL parse) }
Subroutine BEGIN: called CC=1 SCAR=0.0
649 7 my %mail_schemes = (mailto => 1);
650 2 ▶sub parseMailURL($) {
Subroutine parseMailURL: called CC=3 SCAR=11.0
Pod undocumented
651 2 foreach('%', 'mailto:%') {
652 3 my $str = $_;
653 3 $str =~ s/%/$_[0]/g;
654 3 my $url = _url_parse($str, \%mail_schemes);
655 3 ▶ return $url if defined $url;
Branch: 1 branch
BranchTrueFalseTotal
if defined $url 2 1 3
656 }
657 0 return undef;
658 }
659  
660 7 ▶BEGIN { _export qw(multilineText text) }
Subroutine BEGIN: called CC=1 SCAR=0.0
661 518 ▶sub multilineText {
Subroutine multilineText: called CC=3 SCAR=11.0
Pod undocumented
662 518 ▶ if(defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 518 0 518
663 518 my $str = join "", @_;
664 518 ▶ return $str unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 514 4 518
665 4 return split /(?<=\n)/, $str;
666 }
667 }
668  
669 7 ▶BEGIN { _export qw(textURL text) }
Subroutine BEGIN: called CC=1 SCAR=0.0
670 0 ▶sub textURL($) {
Subroutine textURL: not called CC=13 SCAR=52.0
Pod undocumented
671 0 my $url = shift;
672 0 ▶ $url = parseURL($url) if not ref $url;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $url 0 0 0
673 0 ▶ return undef if not defined $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url 0 0 0
674 0 ▶ if($url->scheme eq 'mailto') {
Branch: 1 branch
BranchTrueFalseTotal
if ($url->scheme eq "mailto") 0 0 0
675 0 return $url->to;
676 }
677 0 ▶ if($url->scheme eq 'http' or $url->scheme eq 'https') {
Branch: 1 branch
BranchTrueFalseTotal
if ($url->scheme eq "http" or $url->scheme eq "https") 0 0 0
Condition0%0/3
$url->scheme eq "http" or $url->scheme eq "https"
l!l&&r!l&&!r
000
MC/DC0%0/2
$url->scheme eq "http" or $url->scheme eq "https"
$url->scheme eq "http" $url->scheme eq "https"
Truth table0%0/3
A or B
A= $url->scheme eq "http"B= $url->scheme eq "https"
ABresult
1X1
011
000
678 0 ▶ if(not defined $url->query or $url->query eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $url->query or $url->query eq "") 0 0 0
Condition0%0/3
not defined $url->query or $url->query eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $url->query or $url->query eq ""
not defined $url->query $url->query eq ""
Truth table0%0/3
not(A) or B
A= not defined $url->queryB= $url->query eq ""
ABresult
1X1
011
000
679 0 ▶ if($url->path eq '' or $url->path eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($url->path eq "" or $url->path eq "/") 0 0 0
Condition0%0/3
$url->path eq "" or $url->path eq "/"
l!l&&r!l&&!r
000
MC/DC0%0/2
$url->path eq "" or $url->path eq "/"
$url->path eq "" $url->path eq "/"
Truth table0%0/3
A or B
A= $url->path eq ""B= $url->path eq "/"
ABresult
1X1
011
000
680 0 return $url->host;
681 }
682 0 return $url->host.$url->path;
683 }
684 }
685 0 ▶ if($url->scheme eq 'ftp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($url->scheme eq "ftp") 0 0 0
686 0 return $url->path.' on '.$url->host.' (FTP)';
687 }
688 0 ▶ if($url->scheme eq 'data') {
Branch: 1 branch
BranchTrueFalseTotal
if ($url->scheme eq "data") 0 0 0
689 0 my $m = $url->media_type;
690 0 ▶ if(defined $m) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $m) 0 0 0
691 0 $m =~ s/;.*$//;
692 0 return "Inline data ($m)";
693 }
694 0 return "Inline data";
695 }
696 0 return $url->as_string;
697  
698 }
699  
700 7 ▶BEGIN { _export qw(textALT text) }
Subroutine BEGIN: called CC=1 SCAR=0.0
701 0 ▶sub textALT($) {
Subroutine textALT: not called CC=4 SCAR=30.0
Pod undocumented
702 0 my $url = shift;
703 0 ▶ $url = parseURL($url) if not ref $url;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $url 0 0 0
704 0 ▶ return undef if not defined $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url 0 0 0
705 0 ▶ if($url->scheme eq 'data') {
Branch: 1 branch
BranchTrueFalseTotal
if ($url->scheme eq "data") 0 0 0
706 0 return "[Inline data]";
707 }
708 0 my $path = $url->path;
709 0 $path =~ s#^.*/##;
710 0 return "[$path]";
711 }
712  
713 0 ▶sub _b10_len($) {
Subroutine _b10_len: not called CC=3 SCAR=24.8
714 0 my $n = shift;
715 0 ▶ if($n > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 0) 0 0 0
716 0 return 1+POSIX::floor(log($n)/log(10));
717 }
718 0 ▶ if($n < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 0 0
719 0 return 2+POSIX::floor(log(-$n)/log(10));
720 }
721 0 return 1;
722 }
723  
724 0 ▶sub _max {
Subroutine _max: not called CC=5 SCAR=34.0
725 0 my $max;
726 0 ▶ while(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
727 0 my $val = shift;
728 0 ▶ $max = $val if defined $val and (not defined $max or $val > $max);
Branch: 1 branch
BranchTrueFalseTotal
if defined $val and !defined($max) || $val > $max 0 0 0
Condition0%0/6
defined $val and !defined($max) || $val > $max
!ll&&!rl&&r
000
not defined $max or $val > $max
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $val and !defined($max) || $val > $max
defined $val not defined $max $val > $max
Truth table0%0/4
A and not(B) or C
A= defined $valB= not defined $maxC= $val > $max
ABCresult
0XX0
1000
11X1
1011
729 }
730 0 return $max;
731 }
732  
733 7 ▶BEGIN { _export qw(createListSequence) }
Subroutine BEGIN: called CC=1 SCAR=0.0
734 0 ▶sub createListSequence($;$$) {
Subroutine createListSequence: not called CC=8 SCAR=39.6
Pod undocumented
735 0 my($type,$start,$total) = @_;
736 0 my @list = parseListType($type);
737 0 ▶ $start = 1 unless defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 0 0
738  
739 0 ▶ if(@list and $list[0] eq 'ol') {
Branch: 1 branch
BranchTrueFalseTotal
if (@list and $list[0] eq "ol") 0 0 0
Condition0%0/3
@list and $list[0] eq "ol"
!ll&&!rl&&r
000
MC/DC0%0/2
@list and $list[0] eq "ol"
@list $list[0] eq "ol"
Truth table0%0/3
A and B
A= @listB= $list[0] eq "ol"
ABresult
0X0
100
111
740 0 ▶ my $type = (@list > 1) ? $list[1] : 'decimal';
Branch: 1 branch
BranchTrueFalseTotal
@list > 1 ? : 0 0 0
741  
742 0 if(0) {
743 # Disabled until the generators can be split into separate packages
744 if($type =~ /^(upper|lower)-(alpha|latin|roman|greek)$/i) {
745 my $func = 'textOrder'.ucfirst(lc($2));
746 my $uc = $1 =~ /^upper$/i;
747 $func =~ s/Latin$/Alpha/;
748 {
749 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
750 $func = \&{$func};
751 }
752 if($uc) {
753 0 ▶ return sub { $func->($start++).'.' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
754 } else {
755 0 ▶ return sub { lc $func->($start++).'.' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
756 }
757 }
758 if($type =~ /^(hiragana|katakana)(?:-(iroha))?$/i) {
759 my $func = 'textOrder'.ucfirst(lc($1)).(defined $2 ? uc($2) : '');
760 {
761 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
762 $func = \&{$func};
763 }
764 0 ▶ return sub { $func->($start++).'.' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
765 }
766 if($type =~ /^cjk-ideographic$/i) {
767 0 ▶ return sub { textOrderCJK($start++).'.' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
768 }
769 if($type =~ /^hebrew$/i) {
770 0 ▶ return sub { textOrderHebrew($start++).'.' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
771 }
772 if($type =~ /^georgian$/i) {
773 0 ▶ return sub { textOrderGeorgian($start++).'.' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
774 }
775 if($type =~ /^armenian$/i) {
776 0 ▶ return sub { textOrderArmenian($start++).'.' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
777 }
778 }
779  
780 0 ▶ if($type =~ /^decimal-leading-zero$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^decimal-leading-zero$/i) 0 0 0
781 0 ▶ if(defined $total) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $total) { } 0 0 0
782 0 my $end = $total + $start - 1;
783 0 my $len = _max 3, 1+_b10_len(abs $start), 1+_b10_len(abs $end);
784 0 my $fmt = sprintf '%% 0%dd.', $len;
785 0 ▶ return sub { sprintf($fmt,$start++) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
786 } else {
787 0 ▶ return sub { sprintf("% 03d.", $start++) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
788 }
789 }
790  
791 0 ▶ if(defined $total) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $total) { } 0 0 0
792 0 my $end = $total + $start - 1;
793 0 my $len = _max _b10_len $start, _b10_len $end;
794 0 my $fmt = sprintf '%%%dd.', $len;
795 0 ▶ return sub { sprintf($fmt,$start++) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
796 } else {
797 0 ▶ return sub { sprintf("%d.",$start++) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
798 }
799 }
800 0 ▶ return sub { '*' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
801 }
802  
803 7 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=12.5
804 7 ▶ push @EXPORT_OK, @{$EXPORT_TAGS{ALL}} if exists $EXPORT_TAGS{ALL};
Branch: 1 branch
BranchTrueFalseTotal
if exists $BBCode::Util::EXPORT_TAGS{"ALL"} 7 0 7
805 0 ▶ push @EXPORT, @{$EXPORT_TAGS{DEFAULT}} if exists $EXPORT_TAGS{DEFAULT};
Branch: 1 branch
BranchTrueFalseTotal
if exists $BBCode::Util::EXPORT_TAGS{"DEFAULT"} 0 7 7
806 }
807  
808 7 1;
↑ Summary Parser.pm »