| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 371 | my $tag = shift; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 371 | ▶ | $EXPORT_TAGS{$tag} = [] unless exists $EXPORT_TAGS{$tag}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 2133 | $tag = uc($1); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 2133 | ▶ | if(exists $userTags{$tag}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 199 | ▶ | return $_->Tag if UNIVERSAL::isa($_,'BBCode::Tag'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | croak qq(Invalid reference); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 3283 | ▶ | return uc($1) if /^(:\w+)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return $tag if UNIVERSAL::isa($tag,'BBCode::Tag'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | # Basic HTML/XML escapes | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 122 | s/&/&/g; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 122 | s/</</g; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 122 | s/>/>/g; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 122 | s/"/"/g; | |||||||||||||||||||||||||||||||||||||||||
| 159 | # ' is XML-only | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 122 | s/'/'/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
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 17 | ▶ | return $_->as_bool() if ref $_ and UNIVERSAL::can($_, 'as_bool'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $_ and UNIVERSAL::can($_, "as_bool")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 17 | ▶ | return 1 if /^(?: | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | | ||||||||||||||||||||||||||||||||||||||||||
| 177 | T | TR | TRU | TRUE | | ||||||||||||||||||||||||||||||||||||||||||
| 178 | Y | YE | YES | | ||||||||||||||||||||||||||||||||||||||||||
| 179 | ON | ||||||||||||||||||||||||||||||||||||||||||
| 180 | )$/ix; | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 4 | ▶ | return 0 if /^(?: | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | | ||||||||||||||||||||||||||||||||||||||||||
| 183 | F | FA | FAL | FALS | FALSE | | ||||||||||||||||||||||||||||||||||||||||||
| 184 | N | NO | | ||||||||||||||||||||||||||||||||||||||||||
| 185 | OFF | ||||||||||||||||||||||||||||||||||||||||||
| 186 | )$/ix; | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | return $_ ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 53 | $num =~ s/[\s,_]+//g; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 53 | $num =~ s/^\+//; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 53 | ▶ | return 0 if $num =~ /^-?$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 47 | ▶ | return 0+$1 if $num =~ /^ ( -? \d+ ) $/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 48 | $num =~ s/[\s,_]+//g; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 48 | ▶ | if($num =~ /^ (.*) e (.*) $/ix) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $m and defined $e
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
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 44 | ▶ | if($num =~ /^ ([^.]*) \. ([^.]*) $/x) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 13 | my($i,$f) = ($1,$2); | |||||||||||||||||||||||||||||||||||||||||
| 216 | 13 | $i = parseInt $i; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 13 | ▶ | return undef unless defined $i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 13 | ▶ | return undef unless $f =~ /^(\d*)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 9 | my $decoded = HTML::Entities::decode("&$_;"); | |||||||||||||||||||||||||||||||||||||||||
| 252 | 9 | ▶ | return undef if $decoded eq "&$_;"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | ▶ | if(/^(disc|circle|square|none)$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 45 | my($base,$lo,$hi) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 45 | ▶ | $base = 12 if not defined $base; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 45 | ▶ | $lo = 8 if not defined $lo; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 45 | ▶ | $hi = 72 if not defined $hi; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 17 | my($n,$unit) = ($1,lc $2); | |||||||||||||||||||||||||||||||||||||||||
| 346 | 17 | $n = parseNum $n; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 17 | ▶ | if(defined $n and $n > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $n and $n > 0
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
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 17 | my $conv; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 17 | ▶ | if(exists $conv{$unit}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $lo and $n2 < $lo
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
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | $n = $lo / $conv; | |||||||||||||||||||||||||||||||||||||||||
| 361 | ▶ | } elsif(defined $hi and $n2 > $hi) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $hi and $n2 > $hi
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 9 | my $n = parseNum $1; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 9 | ▶ | if(defined $n and $n > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $n and $n > 0
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
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 9 | $n *= 0.01; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 9 | my $n2 = $n * $base; | |||||||||||||||||||||||||||||||||||||||||
| 380 | 9 | ▶ | if(defined $lo and $n2 < $lo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $lo and $n2 < $lo
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
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | $n = $lo / $base; | |||||||||||||||||||||||||||||||||||||||||
| 382 | ▶ | } elsif(defined $hi and $n2 > $hi) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $hi and $n2 > $hi
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 8 | my $n = 0+$1; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 8 | ▶ | if($n >= 0 and $n < @compat) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$n >= 0 and $n < @compat
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 8 | s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 8 | $_ = lc $_; | |||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 8 | ▶ | return $1 if /^(\w+)$/ and exists $cssColor{$1}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^(\w+)$/ and exists $cssColor{$1}
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}
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 3 | ▶ | return $extraColor{$_} if exists $extraColor{$_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 3 | ▶ | if(s/^#//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | ▶ | return "#$_" if /^ [0-9a-f]{6} $/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 2 | ▶ | return $1 if /^( rgb \( (?: \d+ , ){2} \d+ \) )$/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 2 | ▶ | return $1 if /^( rgba\( (?: \d+ , ){3} \d+ \) )$/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 2 | ▶ | return $1 if /^( rgb \( (?: \d+% , ){2} \d+% \) )$/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 2 | ▶ | return $1 if /^( rgba\( (?: \d+% , ){3} \d+% \) )$/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 35 | ▶ | $ret[0] = lc $1 if s/^([\w+-]+)://; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 35 | $ret[1] = $_; | |||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 35 | ▶ | return @ret if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 25 | $ret[0] = $_; | |||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 25 | ▶ | return @ret if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 19 | ▶ | $ret[0] = $1 if s#^([^/]+)##; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 19 | s#^$#/#; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 19 | $ret[1] = $_; | |||||||||||||||||||||||||||||||||||||||||
| 493 | } elsif(m#^/#) { | ||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $ret[1] = $_; | |||||||||||||||||||||||||||||||||||||||||
| 495 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | return () if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 19 | ▶ | return @ret if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | if(/^ ([^:]*) : ([^:]*) $/x) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 19 | s/:$//; | |||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 19 | s/\.*$/./; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 19 | ▶ | if(/^ ( (?: [\w-]+ \. )+ ) $/x) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 15 | $ret[2] = $1; | |||||||||||||||||||||||||||||||||||||||||
| 538 | 15 | $ret[2] =~ s/\.$//; | |||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 19 | ▶ | goto Failure if not defined $ret[2]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 15 | ▶ | return @ret if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | return \@ret; | |||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 4 | ▶ | Failure: | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 30 | ▶ | return undef unless exists $urltype{$scheme}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | 30 | ▶ | if($urltype{$scheme} > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | 25 | my($rest,$query) = _url_parse_query($opaque); | |||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 25 | ▶ | if($urltype{$scheme} > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 19 | my($auth,$path) = _url_parse_path($rest); | |||||||||||||||||||||||||||||||||||||||||
| 575 | 19 | ▶ | return undef unless defined $path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 19 | ▶ | if($urltype{$scheme} > 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 19 | ▶ | return undef unless defined $auth; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 579 | 19 | my($user,$pass,$host,$port) = _url_parse_server($auth); | |||||||||||||||||||||||||||||||||||||||||
| 580 | 19 | ▶ | return undef unless defined $host; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | 15 | $auth = ''; | |||||||||||||||||||||||||||||||||||||||||
| 583 | 15 | ▶ | if(defined $user) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | $auth .= $user; | |||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | $auth .= ':'.$pass if defined $pass; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | $auth .= '@'; | |||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||
| 588 | 15 | $auth .= $host; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 15 | ▶ | $auth .= ':'.$port if defined $port; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | 15 | ▶ | $rest = join '', map { defined $_ ? $_ : '' } ('//',$auth,$path); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 21 | ▶ | $opaque = join '', map { defined $_ ? $_ : '' } ($rest,$query); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | 26 | ▶ | $str = $scheme.':'.$opaque.(defined $fragment ? $fragment : ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | 26 | ▶ | return undef unless exists $$schemes{$url->scheme}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 602 | 22 | ▶ | return undef if $url->as_string =~ /\bsanity\.check\.example\.com\b/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | 22 | ▶ | return undef if $url->can('userinfo') and defined $url->userinfo; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$url->can("userinfo") and defined $url->userinfo
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
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | 22 | ▶ | return undef if $url->can('host') and not defined $url->host; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$url->can("host") and not defined $url->host
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
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | 22 | ▶ | if($url->scheme eq 'mailto') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | 2 | ▶ | if(exists $safe{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | if($unsafe{$key} =~ /^ ( [\x20-\x7E]+ ) $/x) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | $safe{subject} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | 6 | ▶ | return undef unless exists $safe{to}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 663 | 518 | my $str = join "", @_; | |||||||||||||||||||||||||||||||||||||||||
| 664 | 518 | ▶ | return $str unless wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | ▶ | return undef if not defined $url; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | if($url->scheme eq 'mailto') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | return $url->to; | |||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | ▶ | if($url->scheme eq 'http' or $url->scheme eq 'https') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$url->scheme eq "http" or $url->scheme eq "https"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | ▶ | if(not defined $url->query or $url->query eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $url->query or $url->query eq ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | if($url->path eq '' or $url->path eq '/') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$url->path eq "" or $url->path eq "/"
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 "/"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | return $url->path.' on '.$url->host.' (FTP)'; | |||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | if($url->scheme eq 'data') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | my $m = $url->media_type; | |||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | ▶ | if(defined $m) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | ▶ | return undef if not defined $url; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | ▶ | if($url->scheme eq 'data') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | return 1+POSIX::floor(log($n)/log(10)); | |||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | ▶ | if($n < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | $max = $val if defined $val and (not defined $max or $val > $max); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $val and !defined($max) || $val > $max
not defined $max or $val > $max
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | ▶ | if(@list and $list[0] eq 'ol') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@list and $list[0] eq "ol"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | ▶ | my $type = (@list > 1) ? $list[1] : 'decimal'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | ▶ | if(defined $total) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | ▶ | push @EXPORT, @{$EXPORT_TAGS{DEFAULT}} if exists $EXPORT_TAGS{DEFAULT}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||