DOM/Parser.pm

filter: Statementstmt 89.4% 306 / 342 Branchbran 70.4% 172 / 244 Conditioncond 74.6% 59 / 79 MC/DCmcdc 40.4% 19 / 47 Subroutinesub 100% 23 / 23 Podpod 0.0% 0 / 5 totaltotal 78.2% 579 / 740 CC 164 SCAR 48.4
CC
164
Cov
81%
_decode
333.9
_parse_at_rule
53.5
tokenise
17.1
CRAP 126.5
« DOM/Rule/Style.pm ↑ Summary DOM/Value/Primitive.pm »
1 package CSS::DOM::Parser;
2  
3 22 $VERSION = '0.16';
4  
5 22 ▶use strict; use warnings; no warnings qw 'utf8 parenthesis';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 ▶use re 'taint';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 22 ▶use Carp 1.01 qw 'shortmess croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 22 ▶use CSS::DOM;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 ▶use CSS::DOM::Rule::Style;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 22 ▶use CSS::DOM::Style;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 22 ▶use CSS::DOM::Util 'unescape';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 22 our @CARP_NOT = qw "CSS::DOM CSS::DOM::Rule::Media";
15  
16  
17 # Tokeniser regexps
18  
19 22 my $token_re;
20  
21 # This one has to be outside the scope, because we need it in tokenise.
22 22 my $_optspace = qr/[ \t\r\n\f]*/;
23 {
24  
25 # Vars beginning with _ here are not token regexps, but are used to
26 # build them.
27 22 my $_escape =qr/\\(?:[0-9a-f]{1,6}(?:\r\n|[ \n\r\t\f])?|[^\n\r\f0-9a-f])/i;
28 22 my $_id_start = qr/[_a-zA-Z]|[^\0-\177]|$_escape/;
29 22 my $_id_cont = qr/[_a-zA-Z0-9-]|[^\0-\177]|$_escape/;
30 22 my $_nl = qr/\r\n?|[\n\f]/;
31 22 my $_invalid_qq = qr/"[^\n\r\f\\"]*(?:(?:\\$_nl|$_escape)[^\n\r\f\\"]*)*/;
32 22 my $_invalid_q = qr/'[^\n\r\f\\']*(?:(?:\\$_nl|$_escape)[^\n\r\f\\']*)*/;
33  
34 22 my $ident = qr/-?$_id_start$_id_cont*/;
35 22 my $at = qr/\@$ident/;
36 22 my $str = qr/$_invalid_qq(?:"|\z)|$_invalid_q(?:'|\z)/;
37 22 my $invalid = qr/$_invalid_qq|$_invalid_q/;
38 22 my $hash = qr/#$_id_cont+/;
39 22 my $num = qr/(?=\.?[0-9])[0-9]*(?:\.[0-9]*)?/;
40 22 my $percent = qr/$num%/;
41 22 my $dim = qr/$num$ident/;
42 22 my $url = qr/url\($_optspace(?:
43 $str
44 |
45 [^\0- "'()\\\x7f]*(?:$_escape[^\0- "'()\\\x7f]*)*
46 )$_optspace(?:\)|\z)/x;
47 22 my $uni_range = qr/U\+[0-9A-F?]{1,6}(?:-[0-9a-f]{1,6})?/i;
48 22 my $space = qr/(?:[ \t\r\n\f]+|\/\*.*?(?:\*\/|\z))[ \t\r\n\f]*
49 (?:\/\*.*?(?:\*\/|\z)[ \t\r\n\f]*)*/xs;
50 22 my $function = qr/$ident\(/;
51  
52 # Literal tokens are as follows:
53 # <!-- --> ; { } ( ) [ ] ~= |= , :
54  
55 # The order of some tokens is important. $url, $uni_range and $function
56 # have to come before $ident. $url has to come before $function. $percent
57 # and $dim have to come before $num.
58 22 $token_re = qr/\G(?:
59 ($url)|($uni_range)|($function)|($ident)|($at)|($str)|($invalid)|
60 ($hash)|($percent)|($dim)|($num)|(<!--|-->)|(;)|({)|(})|(\()|(\))
61 |(\[)|(])|($space)|(~=)|(\|=)|(,)|(:)|(.)
62 )/xs;
63  
64 } # end of tokeniser regexps
65  
66 # tokenise returns a string of token types in addition to the array of
67 # tokens so that we can apply grammar rules using regexps. The types are
68 # as follows:
69 # u url
70 # U unicode range
71 # f function
72 # i identifier
73 # @ at keyword
74 # ' string
75 # " invalid string (unterminated)
76 # # hash
77 # % percentage
78 # D dimension
79 # 1 number (not 0, because we want it true)
80 # < html comment delimiter
81 # s space/comments
82 # ~ ~=
83 # | |=
84 # d delimiter (miscellaneous character)
85 # The characters ;{}()[],: represent themselves. The comma and colon are
86 # actually delimiters according to the CSS 2.1 spec, but it’s more conveni-
87 # ent to have them as their own tokens.
88 # ~~~ It might actually make the code cleaner if we make them all their own
89 # tokens, in which case we can provide a $delim_re for matching against a
90 # token type string.
91  
92 1991 ▶sub tokenise { warn caller unless defined $_[0];for (''.shift) {
Subroutine tokenise: called CC=17 SCAR=28.4
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 1991 1991
93 1991 my($tokens,@tokens)='';
94 1991 ▶ while(/$token_re/gc){
Branch: 1 branch
BranchTrueFalseTotal
if (/$token_re/cg) 6967 1991 8958
95 6967 my $which = (grep defined $+[$_], 1..$#+)[0];
96 22 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
97 6967 push @tokens, $$which;
98 22 ▶ no warnings qw]qw];
Subroutine BEGIN: called CC=1 SCAR=0.0
99 6967 $tokens .=
100 qw/u U f i @ ' " # % D 1 < ; { } ( ) [ ] s ~ | , : d/
101 [$which-1];
102  
103 # We need to close unterminated tokens for the sake of
104 # serialisation. If we don’t, then too many other parts of
105 # the code base have to deal with it.
106 6967 ▶ if($tokens =~ /'\z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tokens =~ /'\z/) { } 127 6840 6967
elsif ($tokens =~ /u\z/) { } 75 6765 6840
107 127 ▶ $tokens[-1] =~ /^(')[^'\\]*(?:\\.[^'\\]*)*\z
Branch: 1 branch
BranchTrueFalseTotal
$tokens[-1] =~ /^(')[^'\\]*(?:\\.[^'\\]*)*\z | ^(")[^"\\]*(?:\\.[^"\\]*)*\z/sx and $tokens[-1] .= $1 || $2 14 113 127
Condition66%2/3
$1 || $2
l!l&&r!l&&!r
590
MC/DC0%0/2
$1 || $2
$1 $2
Truth table66%2/3
A || B
A= $1B= $2
ABresult
1X1
011
000
108 |
109 ^(")[^"\\]*(?:\\.[^"\\]*)*\z/xs
110 and $tokens[-1] .= $1 || $2;
111 }
112 elsif($tokens =~ /u\z/) {
113 75 (my $copy = $tokens[-1]) =~ s/^url\($_optspace(?:
114 (')[^'\\]*(?:\\.[^'\\]*)*
115 |
116 (")[^"\\]*(?:\\.[^"\\]*)*
117 |
118 [^)\\]*(?:\\.[^)\\]*)*
119 )//sox;
120 75 ▶ my $str_delim = $1||$2;
Condition100%3/3
$1 || $2
l!l&&r!l&&!r
81057
MC/DC100%2/2
$1 || $2
$1 $2
Truth table100%3/3
A || B
A= $1B= $2
ABresult
1X1
011
000
121 75 ▶ $str_delim and $copy!~s/^['"]$_optspace//o
Branch: 1 branch
BranchTrueFalseTotal
$str_delim and not $copy =~ s/^['"]$_optspace//o and $tokens[-1] .= $str_delim 6 69 75
Condition100%3/3
$str_delim and not $copy =~ s/^['"]$_optspace//o
!ll&&!rl&&r
57126
MC/DC100%2/2
$str_delim and not $copy =~ s/^['"]$_optspace//o
$str_delim not $copy =~ s/^['"]$_optspace//o
Truth table100%3/3
A and not(B)
A= $str_delimB= not $copy =~ s/^['"]$_optspace//o
ABresult
0X0
100
111
122 and $tokens[-1] .= $str_delim;
123 75 ▶ $copy or $tokens[-1] .= ')';
Branch: 1 branch
BranchTrueFalseTotal
$copy or $tokens[-1] .= ')' 14 61 75
124 }
125 }
126 # This can’t ever happen:
127 1991 ▶ pos and pos() < length
Branch: 1 branch
BranchTrueFalseTotal
pos $_ and pos $_ < length $_ and die q[CSS::DOM::Parser internal error (please report this): Can't tokenise ] . substr($_, pos $_) 0 1991 1991
Condition66%2/3
pos $_ and pos $_ < length $_
!ll&&!rl&&r
519860
MC/DC0%0/2
pos $_ and pos $_ < length $_
pos $_ pos $_ < length $_
Truth table66%2/3
A and B
A= pos $_B= pos $_ < length $_
ABresult
0X0
100
111
128 and die "CSS::DOM::Parser internal error (please report this):"
129 ." Can't tokenise " .substr $_,pos;
130  
131 # close bracketed constructs: again, we do this here so that other
132 # pieces of code scattered all over the place (including the reg-
133 # exps below, which would need things like ‘(?:\)|\z)’)
134 # don’t have to.
135 1991 my $brack_count = (()=$tokens=~/[(f]/g)-(()=$tokens=~/\)/g)
136 + (()=$tokens=~/\[/g)-(()=$tokens=~/]/g)
137 + (()=$tokens=~/{/g)-(()=$tokens=~/}/g);
138 1991 my $tokens_copy = reverse $tokens;
139 1991 for(1..$brack_count) {
140 74 $tokens_copy =~ s/.*?([[{(f])//;
141 74 ▶ push @tokens, $1 eq'['?']':$1 eq'{'?'}':')';
Branch: 2 branches
BranchTrueFalseTotal
$1 eq '[' ? : 3 71 74
$1 eq '{' ? : 59 12 71
142 74 $tokens .= $tokens[-1];
143 }
144  
145 1991 return $tokens,\@tokens, ;
146 }}
147  
148 # Each statement is either an @ rule or a ruleset (style rule)
149 # @ rule syntax is
150 # @ s? any* followed by block or ;
151 # A block is { s? (any|block|@ s?|; s?)* } s?
152 # ruleset syntax is
153 # any* { s? [d,:]? ident s? : s? (any|block|@ s?)+
154 # (; s? [d,:]? ident s? : s? (any|block|@ s?)+)* } s?
155 # "any" means
156 # ( [i1%D'd,:u#U~|] | f s? any* \) | \(s? any \) | \[ s? any \] ) s?
157 # That’s the ‘future-compatible’ CSS syntax. Below, we sift out the valid
158 # CSS 2.1 rules to put them in the right classes. Everything else goes in
159 # ‘Unknown’.
160  
161 # Methods beginning with _parse truncate the arguments (a string of token
162 # types and an array ref of tokens) and return an object. What’s left of
163 # the args is whatever couldn’t be parsed. If the args were parsed in their
164 # entirety, they end up blank.
165  
166 22 our $any_re; our $block_re;
167 22 ▶no warnings 'regexp';
Subroutine BEGIN: called CC=1 SCAR=0.0
168 # Although we include invalid strings (") in the $any_re, they are not
169 # actually valid, but cause the enclosing property declaration or rule to
170 # be ignored.
171 $any_re =
172 qr/(?:
173 [i1%D'"d,:u#U~|]
174 |
175 [f(]s?(??{$any_re})*\)
176 |
177 \[s?(??{$any_re})*]
178 22 )s?/x;
179 $block_re =
180 22 qr/{s?(?:(??{$any_re})|(??{$block_re})|[\@;]s?)*}s?/;
181  
182 sub tokenise_value { # This is for ::Style to use. It dies if there are
183 # tokens left over.
184 1054 ▶ my ($types, $tokens) = tokenise($_[0]);
Subroutine tokenise_value: called CC=2 SCAR=6.9
Pod undocumented
185 1054 ▶ $types =~ /^s?(?:$any_re|$block_re|\@s?)*\z/ or die
Branch: 1 branch
BranchTrueFalseTotal
$types =~ /^s?(?:$CSS::DOM::Parser::any_re|$CSS::DOM::Parser::block_re|\@s?)*\z/ or die "Invalid property value: $_[0]" 1 1053 1054
186 "Invalid property value: $_[0]";
187 1053 return $types, $tokens;
188 }
189  
190 sub parse { # Don’t shift $_[0] off @_. We’d end up copying it if we did
191 # that--something we ought to avoid, in case it’s huge.
192 74 ▶ my $pos = pos $_[0];
Subroutine parse: called CC=10 SCAR=23.0
Pod undocumented
193 74 my(%args) = @_[1..$#_];
194 74 my $src;
195 74 ▶ if( $args{qw[encoding_hint decode][exists $args{decode}]} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{("encoding_hint", "decode")[exists $args{"decode"}]}) 22 52 74
196 22 $src = _decode(@_);
197 22 ▶ defined $src or shift, return new CSS::DOM @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $src or shift(), (return "CSS::DOM"->new(@_)) 0 22 22
198 }
199 74 ▶ my($types,$tokens,) = tokenise defined $src ? $src : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
defined $src ? : 22 52 74
200 74 my $sheet = new CSS::DOM @_[1..$#_];
201 74 my $stmts = $sheet->cssRules;
202 74 eval { for($types) {
203 74 ▶ while($_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_) 103 58 161
204 103 ▶ s/^([s<]+)//
Branch: 1 branch
BranchTrueFalseTotal
s/^([s<]+)// and splice @$tokens, 0, length $1 20 83 103
205 and splice @$tokens, 0, length $1;
206 103 my $tokcount = @$tokens;
207 103 ▶ if(/^@/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^@/) { } 44 59 103
208 44 push @$stmts,
209 _parse_at_rule($_,$tokens,$sheet);
210 }
211 else {
212 59 push @$stmts, _parse_ruleset(
213 $_,$tokens,$sheet
214 );
215 }
216 96 ▶ if($tokcount == @$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokcount == @$tokens) 10 86 96
217 10 ▶ $types and _expected("rule",$tokens)
Branch: 1 branch
BranchTrueFalseTotal
$types and _expected("rule", $tokens) 9 1 10
218 }
219 }
220 }};
221 74 pos $_[0] = $pos;
222 74 return $sheet;
223 }
224  
225 sub parse_statement {
226 177 ▶ my $pos = pos $_[0];
Subroutine parse_statement: called CC=7 SCAR=19.5
Pod undocumented
227 177 my($types,$tokens,) = tokenise $_[0];
228 177 my $stmt;
229 177 eval{ for($types) {
230 177 ▶ s/^s//
Branch: 1 branch
BranchTrueFalseTotal
s/^s// and shift @$tokens 14 163 177
231 and shift @$tokens;
232 177 ▶ if(/^@/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^@/) { } 146 31 177
233 146 $stmt = _parse_at_rule($_,$tokens,$_[1]);
234 }
235 else {
236 #use DDS; Dump [$_,$tokens];
237 31 ▶ $stmt = _parse_ruleset(
Branch: 1 branch
BranchTrueFalseTotal
$stmt = _parse_ruleset($_, $tokens, $_[1]) or last 2 29 31
238 $_,$tokens,$_[1]
239 ) or last;
240 # use DDS; Dump $stmt;
241 }
242 }};
243 177 pos $_[0] = $pos;
244 177 ▶ $@ = length $types ? shortmess "Invalid CSS statement"
Branch: 2 branches
BranchTrueFalseTotal
unless $@ 177 0 177
length $types ? : 7 170 177
245 : ''
246 unless $@;
247 177 return $stmt;
248 }
249  
250 sub parse_style_declaration {
251 398 ▶ my $pos = pos $_[0];
Subroutine parse_style_declaration: called CC=4 SCAR=13.9
Pod undocumented
252 #use DDS; Dump tokenise $_[0]; pos $_[0] = $pos;
253 398 my @tokens = tokenise $_[0];
254 398 ▶ $tokens[0] =~ s/^s// and shift @{$tokens[1]};
Branch: 1 branch
BranchTrueFalseTotal
$tokens[0] =~ s/^s// and shift @{$tokens[1];} 2 396 398
255 398 ▶ $@ = (
Branch: 1 branch
BranchTrueFalseTotal
(my $style = _parse_style_declaration(@tokens, undef, @_[1 .. $#_])) && !$tokens[0] ? : 397 1 398
Condition66%2/3
my $style = _parse_style_declaration(@tokens, undef, @_[1 .. $#_]) and not $tokens[0]
!ll&&!rl&&r
01397
MC/DC50%1/2
my $style = _parse_style_declaration(@tokens, undef, @_[1 .. $#_]) and not $tokens[0]
my $style = _parse_style_declaration(@tokens, undef, @_[1 .. $#_]) not $tokens[0]
Truth table66%2/3
A and not(B)
A= my $style = _parse_style_declaration(@tokens, undef, @_[1 .. $#_])B= not $tokens[0]
ABresult
0X0
100
111
256 my $style = _parse_style_declaration(
257 @tokens,undef,@_[1..$#_]
258 ) and!$tokens[0]
259 ) ? '' : shortmess 'Invalid style declaration';
260 398 pos $_[0] = $pos;
261 398 return $style;
262 }
263  
264 # This one will die if it fails to match a rule. We only call it when we
265 # are certain that we could only have an @ rule.
266 # This accepts as an optional third arg the parent rule or stylesheet.
267 190 ▶sub _parse_at_rule { for (shift) { for my $tokens (shift) {
Subroutine _parse_at_rule: called CC=46 SCAR=39.8
268 190 my $unesc_at = lc unescape(my $at = shift @$tokens);
269 190 my $type;
270 190 s/^@//;
271 190 ▶ if($unesc_at eq '@media'
Branch: 4 branches
BranchTrueFalseTotal
if ($unesc_at eq '@media' and s/^(s?is?(?:,s?is?)*\{)//) { } 66 124 190
elsif ($unesc_at eq '@page' and s/^((?:s?:i)?)(s?{s?)// or $unesc_at eq '@font-face' and s/^()(s?{s?)//) { } 22 102 124
elsif ($unesc_at eq '@import' and s/^s?([u'])s?(is?(?:,s?is?)*)?(?:;s?|\z)//) { } 43 59 102
elsif ($at eq '@charset' and @$tokens >= 3 and $tokens->[0] eq ' ' and $tokens->[1] =~ /^"/ and s/^s';s?//) { } 22 37 59
Condition100%3/3
$unesc_at eq "\@media" and s/^(s?is?(?:,s?is?)*\{)//
!ll&&!rl&&r
1131166
MC/DC100%2/2
$unesc_at eq "\@media" and s/^(s?is?(?:,s?is?)*\{)//
$unesc_at eq "\@media" s/^(s?is?(?:,s?is?)*\{)//
Truth table100%3/3
A and B
A= $unesc_at eq "\@media"B= s/^(s?is?(?:,s?is?)*\{)//
ABresult
0X0
100
111
272 && s/^(s?is?(?:,s?is?)*\{)//) {
273 # There’s a good chance
274 # this is a @media rule,
275 # but if what follows this
276 # regexp match turns out
277 # not to be a valid set of
278 # rulesets, we have an
279 # unknown rule.
280 66 my $header = $1;
281 66 my @header = splice @$tokens,
282 0,
283 length $1;
284 # set aside all body tokens in case this turns out to be
285 # an unknown rule
286 66 my ($body,@body);
287 66 ▶ "{$_" =~ /^$block_re/
Branch: 1 branch
BranchTrueFalseTotal
("{$_") =~ /^$CSS::DOM::Parser::block_re/ ? : 66 0 66
288 ? ($body = substr($_,0,$+[0]-1),
289 @body = @$tokens[0..$+[0]-2])
290 : croak "Invalid block in \@media rule";
291  
292 #use DDS; Dump $body, \@body;
293 # We need to record the number of tokens we have now, so
294 # that, if we revert to ‘unknown’ status, we can remove the
295 # right number of tokens.
296 66 my $tokens_to_begin_with = length;
297 66 ▶ s/^s// and shift @$tokens;
Branch: 1 branch
BranchTrueFalseTotal
s/^s// and shift @$tokens 31 35 66
298 66 my @rulesets;
299 66 ▶ while($_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_) 94 0 94
300 94 ▶ push @rulesets, _parse_ruleset ($_, $tokens)||last;
Condition100%2/2
_parse_ruleset($_, $tokens) || (last)
l!l
2866
MC/DC100%1/1
_parse_ruleset($_, $tokens) || (last)
_parse_ruleset($_, $tokens)
Truth table100%2/2
A
A= _parse_ruleset($_, $tokens)
Aresult
11
00
301 }
302
303 66 ▶ if(s/^}s?//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^}s?//) { } 49 17 66
304 49 splice @$tokens, 0, $+[0];
305 49 require CSS::DOM::Rule::Media;
306 49 ▶ my $rule = new CSS::DOM::Rule::Media $_[0]||();
Condition66%2/3
$_[0] || ()
l!l&&r!l&&!r
4630
MC/DC0%0/2
$_[0] || ()
$_[0] ()
Truth table66%2/3
A || B
A= $_[0]B= ()
ABresult
1X1
011
000
307 49 @{$rule->cssRules} = @rulesets;
308 $_->_set_parentRule($rule),
309 $_[0] &&$_->_set_parentStyleSheet($_[0])
310 49 ▶ for @rulesets;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] and $_->_set_parentStyleSheet($_[0]) 27 0 27
311 49 my $media = $rule->media;
312 49 ▶ while($header =~ /i/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header =~ /i/g) 82 49 131
313 82 push @$media, unescape($header[$-[0]]);
314 }
315 49 return $rule;
316 }
317 else {
318 # ignore rules w/invalid strings
319 17 ▶ $body =~ /"/ and return;
Branch: 1 branch
BranchTrueFalseTotal
$body =~ /"/ and return 0 17 17
320  
321 17 my $length = $tokens_to_begin_with-length $body;
322 17 ▶ $_ = $length ? substr $_, -$length : '';
Branch: 1 branch
BranchTrueFalseTotal
$length ? : 1 16 17
323 17 @$tokens = @$tokens[-$length..-1];
324  
325 17 ▶ $body =~ s/s\z// and pop @body;
Branch: 1 branch
BranchTrueFalseTotal
$body =~ s/s\z// and pop @body 5 12 17
326 17 require CSS::DOM::Rule;
327 17 ▶ (my $rule = new CSS::DOM::Rule $_[0]||())
Condition33%1/3
$_[0] || ()
l!l&&r!l&&!r
1700
MC/DC0%0/2
$_[0] || ()
$_[0] ()
Truth table33%1/3
A || B
A= $_[0]B= ()
ABresult
1X1
011
000
328 ->_set_tokens(
329 "\@$header$body",
330 [$at,@header,@body]
331 );
332 17 return $rule;
333 }
334 }
335 ▶ elsif($unesc_at eq '@page' && s/^((?:s?:i)?)(s?{s?)//
Condition88%8/9
$unesc_at eq "\@page" and s/^((?:s?:i)?)(s?{s?)// or $unesc_at eq "\@font-face" and s/^()(s?{s?)//
l!l&&r!l&&!r
148102
$unesc_at eq "\@page" and s/^((?:s?:i)?)(s?{s?)//
!ll&&!rl&&r
109114
$unesc_at eq "\@font-face" and s/^()(s?{s?)//
!ll&&!rl&&r
10208
MC/DC75%3/4
$unesc_at eq "\@page" and s/^((?:s?:i)?)(s?{s?)// or $unesc_at eq "\@font-face" and s/^()(s?{s?)//
$unesc_at eq "\@page" s/^((?:s?:i)?)(s?{s?)// $unesc_at eq "\@font-face" s/^()(s?{s?)//
Truth table57%4/7
A and B or C and D
A= $unesc_at eq "\@page"B= s/^((?:s?:i)?)(s?{s?)//C= $unesc_at eq "\@font-face"D= s/^()(s?{s?)//
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
336 ||$unesc_at eq '@font-face' && s/^()(s?{s?)// ) {
337 22 my $selector = "\@$1";
338 22 my @selector = ('@page', splice @$tokens, 0, $+[1]);
339 22 my @block_start =
340 splice @$tokens, 0, length(my $block_start = $2);
341  
342 22 my $class = qw[FontFace Page][$unesc_at eq '@page'];
343  
344 # Unfortunately, these two lines may turn out to
345 # be a waste.
346 22 require "CSS/DOM/Rule/$class.pm";
347 22 ▶ my $style = (
Condition66%2/3
$_[0] || ()
l!l&&r!l&&!r
2020
MC/DC0%0/2
$_[0] || ()
$_[0] ()
Truth table66%2/3
A || B
A= $_[0]B= ()
ABresult
1X1
011
000
348 my $rule = "CSS::DOM::Rule::$class"->new(
349 $_[0]||()
350 )
351 ) -> style;
352  
353 22 $style = _parse_style_declaration($_,$tokens,$style);
354 22 ▶ if($style) {
Branch: 1 branch
BranchTrueFalseTotal
if ($style) { } 20 2 22
355 20 ▶ s/^}s?// and splice @$tokens, 0, $+[0]; # remove }
Branch: 1 branch
BranchTrueFalseTotal
s/^}s?// and splice @$tokens, 0, $+[0] 20 0 20
356 20 ▶ $rule->selectorText(join '', @selector)
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "Page" 12 8 20
357 if $class eq 'Page';
358 20 return $rule;
359 }
360 else {
361 2 ▶ "{$_" =~ /^$block_re/
Branch: 1 branch
BranchTrueFalseTotal
("{$_") =~ /^$CSS::DOM::Parser::block_re/ or croak("Invalid block in \@page rule") 2 0 2
362 or croak "Invalid block in \@page rule";
363 0 $selector .= $block_start .substr($_,0,$+[0]-1,''),
364 push @selector, @block_start ,
365 splice @$tokens, 0, $+[0]-1;
366  
367 # ignore rules w/invalid strings
368 0 ▶ $selector =~ /"/ and return;
Branch: 1 branch
BranchTrueFalseTotal
$selector =~ /"/ and return 0 0 0
369  
370 0 ▶ $selector =~ s/s\z// and pop @selector;
Branch: 1 branch
BranchTrueFalseTotal
$selector =~ s/s\z// and pop @selector 0 0 0
371  
372 0 require CSS'DOM'Rule;
373 0 ▶ (my $rule = new CSS::DOM::Rule $_[0]||())
Condition0%0/3
$_[0] || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] || ()
$_[0] ()
Truth table0%0/3
A || B
A= $_[0]B= ()
ABresult
1X1
011
000
374 ->_set_tokens(
375 $selector,\@selector
376 # not exactly a selector any more
377 );
378 0 return $rule;
379 }
380 }
381 ▶ elsif($unesc_at eq '@import'
Condition100%3/3
$unesc_at eq "\@import" and s/^s?([u'])s?(is?(?:,s?is?)*)?(?:;s?|\z)//
!ll&&!rl&&r
58143
MC/DC100%2/2
$unesc_at eq "\@import" and s/^s?([u'])s?(is?(?:,s?is?)*)?(?:;s?|\z)//
$unesc_at eq "\@import" s/^s?([u'])s?(is?(?:,s?is?)*)?(?:;s?|\z)//
Truth table100%3/3
A and B
A= $unesc_at eq "\@import"B= s/^s?([u'])s?(is?(?:,s?is?)*)?(?:;s?|\z)//
ABresult
0X0
100
111
382 && s/^s?([u'])s?(is?(?:,s?is?)*)?(?:;s?|\z)//) {
383 43 my($url_type,$media_token_types) = ($1,$2);
384 43 my $url = $$tokens[$-[1]];
385 43 ▶ my @media_tokens = $2?@$tokens[$-[2]..$+[2]]:();
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 5 38 43
386 43 splice @$tokens, 0, $+[0];
387 43 require CSS::DOM::Rule::Import;
388 43 ▶ my $rule = new CSS::DOM::Rule::Import $_[0]||();
Condition66%2/3
$_[0] || ()
l!l&&r!l&&!r
24190
MC/DC0%0/2
$_[0] || ()
$_[0] ()
Truth table66%2/3
A || B
A= $_[0]B= ()
ABresult
1X1
011
000
389 43 $rule->_set_url_token($url_type,$url);
390 43 ▶ @media_tokens or return $rule;
Branch: 1 branch
BranchTrueFalseTotal
@media_tokens or return $rule 38 5 43
391 5 my $media = $rule->media;
392 5 ▶ while($media_token_types =~ /i/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($media_token_types =~ /i/g) 9 5 14
393 9 push @$media, unescape($media_tokens[$-[0]]);
394 }
395 5 return $rule;
396 }
397 ▶ elsif($at eq '@charset' # NOT $unesc_at!
Condition100%12/12
$at eq "\@charset" and @$tokens >= 3 and $tokens->[0] eq " " and $tokens->[1] =~ /^"/ and s/^s';s?//
!ll&&!rl&&r
36122
$at eq "\@charset" and @$tokens >= 3 and $tokens->[0] eq " " and $tokens->[1] =~ /^"/
!ll&&!rl&&r
35123
$at eq "\@charset" and @$tokens >= 3 and $tokens->[0] eq " "
!ll&&!rl&&r
34124
$at eq "\@charset" and @$tokens >= 3
!ll&&!rl&&r
33125
MC/DC100%5/5
$at eq "\@charset" and @$tokens >= 3 and $tokens->[0] eq " " and $tokens->[1] =~ /^"/ and s/^s';s?//
$at eq "\@charset" @$tokens >= 3 $tokens->[0] eq " " $tokens->[1] =~ /^"/ s/^s';s?//
Truth table100%6/6
A and B and C and D and E
A= $at eq "\@charset"B= @$tokens >= 3C= $tokens->[0] eq " "D= $tokens->[1] =~ /^"/E= s/^s';s?//
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
398 && @$tokens >= 3 # @charset rule syntax
399 && $tokens->[0] eq ' ' # is stricter than the
400 && $tokens->[1] =~ /^"/ # tokenisation rules.
401 && s/^s';s?//) {
402 22 my $esc_enc = $tokens->[1];
403 22 splice @$tokens, 0, $+[0];
404 22 require CSS::DOM::Rule::Charset;
405 22 ▶ my $rule = new CSS::DOM::Rule::Charset $_[0]||();
Condition66%2/3
$_[0] || ()
l!l&&r!l&&!r
2020
MC/DC0%0/2
$_[0] || ()
$_[0] ()
Truth table66%2/3
A || B
A= $_[0]B= ()
ABresult
1X1
011
000
406 22 $rule->encoding(unescape(substr $esc_enc, 1,-1));
407 22 return $rule;
408 }
409 else { # unwist
410 #warn $_;
411 37 ▶ s/^(s?(??{$any_re})*(?:(??{$block_re})|(?:;s?|\z)))//
Branch: 1 branch
BranchTrueFalseTotal
s/^(s?(??{ $CSS::DOM::Parser::any_re; })*(?:(??{ $CSS::DOM::Parser::block_re; })|(?:;s?|\z)))// or croak("Invalid $at rule") 5 32 37
412 or croak "Invalid $at rule";
413 32 my ($types,@tokens) = ("\@$1",$at,splice @$tokens,0,$+[0]);
414 32 ▶ $types =~ /"/ and return; # ignore rules w/invalid strings
Branch: 1 branch
BranchTrueFalseTotal
$types =~ /"/ and return 1 31 32
415 31 ▶ $types =~ s/s\z// and pop @tokens;
Branch: 1 branch
BranchTrueFalseTotal
$types =~ s/s\z// and pop @tokens 8 23 31
416 31 require CSS'DOM'Rule;
417 31 ▶ (my $rule = new CSS::DOM::Rule $_[0]||())
Condition66%2/3
$_[0] || ()
l!l&&r!l&&!r
2830
MC/DC0%0/2
$_[0] || ()
$_[0] ()
Truth table66%2/3
A || B
A= $_[0]B= ()
ABresult
1X1
011
000
418 ->_set_tokens(
419 $types, \@tokens
420 );
421 31 return $rule;
422 }
423 }}}
424  
425 184 ▶sub _parse_ruleset { for (shift) {
Subroutine _parse_ruleset: called CC=8 SCAR=21.0
426 # Just return if there isn’t a ruleset
427 184 ▶ s/(^($any_re*)\{s?(?:$any_re|$block_re|[\@;]s?)*}s?)//x
Branch: 1 branch
BranchTrueFalseTotal
s/(^($CSS::DOM::Parser::any_re*)\{s?(?:$CSS::DOM::Parser::any_re|$CSS::DOM::Parser::block_re|[\@;]s?)*}s?)//x or return 78 106 184
428 or return;
429 index $2,'"' =>== -1 or
430 106 ▶ splice (@{+shift}, 0, $+[0]), return;
Branch: 1 branch
BranchTrueFalseTotal
index($2, "\"") == -1 or splice(@{shift();}, 0, $+[0]), return 1 105 106
431  
432 105 for(my $x = $1) {
433 105 my $tokens = [splice @{+shift}, 0, $+[0]];
434  
435 105 ▶ (my $ruleset = new CSS::DOM::Rule::Style $_[0]||())
Condition66%2/3
$_[0] || ()
l!l&&r!l&&!r
65400
MC/DC0%0/2
$_[0] || ()
$_[0] ()
Truth table66%2/3
A || B
A= $_[0]B= ()
ABresult
1X1
011
000
436 ->_set_selector_tokens(_parse_selector($_,$tokens));
437  
438 105 ▶ s/^{s?// and splice @$tokens, 0, $+[0]; # remove {
Branch: 1 branch
BranchTrueFalseTotal
s/^{s?// and splice @$tokens, 0, $+[0] 105 0 105
439  
440 #use DDS; Dump$_,$tokens;
441 105 _parse_style_declaration($_,$tokens,$ruleset->style);
442  
443 105 ▶ s/^}s?// and splice @$tokens, 0, $+[0]; # remove }
Branch: 1 branch
BranchTrueFalseTotal
s/^}s?// and splice @$tokens, 0, $+[0] 105 0 105
444  
445  
446 105 return $ruleset
447
448 }}}
449  
450 105 ▶sub _parse_selector { for (shift) { for my $tokens (shift) {
Subroutine _parse_selector: called CC=5 SCAR=16.1
451 105 my($selector,@selector) = '';
452 105 ▶ if(s/^($any_re+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^($CSS::DOM::Parser::any_re+)//) 78 27 105
453 78 $selector = $1;
454 78 push @selector, splice @$tokens, 0, length $1;
455 }
456 105 ▶ $selector =~ s/s\z// and pop @selector;
Branch: 1 branch
BranchTrueFalseTotal
$selector =~ s/s\z// and pop @selector 38 67 105
457 105 return $selector, \@selector;
458 }}}
459  
460 # This one takes optional extra args:
461 # 2) the style decl object to add properties to
462 # 3..) extra args to pass to the style obj’s constructor if 2 is undef
463 525 ▶sub _parse_style_declaration { for (shift) { for my $tokens (shift) {
Subroutine _parse_style_declaration: called CC=11 SCAR=24.0
464 # return if there isn’t one
465 525 ▶ /^(?:$any_re|$block_re|[\@;]s?)*(?:}s?|\z)/x
Branch: 1 branch
BranchTrueFalseTotal
/^(?:$CSS::DOM::Parser::any_re|$CSS::DOM::Parser::block_re|[\@;]s?)*(?:}s?|\z)/x or return 2 523 525
466 or return;
467  
468 523 ▶ my $style = shift||new CSS::DOM::Style @_;
Condition66%2/3
shift() || 'CSS::DOM::Style'->new(@_)
l!l&&r!l&&!r
1253980
MC/DC0%0/2
shift() || 'CSS::DOM::Style'->new(@_)
shift() 'CSS::DOM::Style'->new(@_)
Truth table66%2/3
A || B
A= shift()B= 'CSS::DOM::Style'->new(@_)
ABresult
1X1
011
000
469  
470 {
471 523 ▶ if(s/^is?:s?((?:$any_re|$block_re|\@s?)+)//) {
Branch: 2 branches
BranchTrueFalseTotal
if (s/^is?:s?((?:$CSS::DOM::Parser::any_re|$CSS::DOM::Parser::block_re|\@s?)+)//) { } 633 54 687
elsif (s/^;s?//) { } 21 33 54
472 633 my ($prop) = splice @$tokens, 0, $-[1];
473 633 my $types = $1;
474 633 my @tokens = splice @$tokens, 0, length $1;
475 633 ▶ unless($types =~ /"/) { # ignore invalid strings
Branch: 1 branch
BranchTrueFalseTotal
unless ($types =~ /"/) 631 2 633
476 631 ▶ $types =~ s/s\z// and pop @tokens;;
Branch: 1 branch
BranchTrueFalseTotal
$types =~ s/s\z// and pop @tokens 45 586 631
477 631 $style->_set_property_tokens(
478 unescape($prop),$types,\@tokens
479 );
480 }
481 633 ▶ s/^;s?// and splice(@$tokens, 0, $+[0]), redo;
Branch: 1 branch
BranchTrueFalseTotal
s/^;s?// and splice(@$tokens, 0, $+[0]), redo 142 491 633
482 }
483 elsif(s/^;s?//) {
484 21 splice @$tokens, 0, $+[0]; redo;
485 }
486 else {
487 # Ignorable declaration
488 33 s/^(?:$any_re|$block_re|\@s?)*//;
489 33 splice @$tokens, 0, $+[0];
490 33 ▶ s/^;s?// and splice(@$tokens, 0, $+[0]), redo;
Branch: 1 branch
BranchTrueFalseTotal
s/^;s?// and splice(@$tokens, 0, $+[0]), redo 1 32 33
491 }
492 # else last
493 }
494  
495 523 return $style;
496 }}}
497  
498 sub _expected {
499 9 ▶ my $tokens = pop;
Subroutine _expected: called CC=3 SCAR=11.0
500 9 ▶ croak
Branch: 2 branches
BranchTrueFalseTotal
10 < $tokens->$#* ? : 3 6 9
$tokens->$#* > 10 ? : 3 6 9
501 "Syntax error: expected $_[0] but found '"
502 .join('',@$tokens[
503 0..(10<$#$tokens?10 : $#$tokens)
504 ]) . ($#$tokens > 10 ? '...' : '') . "'";
505 }
506  
507 22 ▶sub _decode { my $at; for(''.shift) {
Subroutine _decode: called CC=61 SCAR=58.1
508 # ~~~ Some of this is repetitive and could probably be compressed.
509 22 require Encode;
510 22 ▶ if(/^(\xef\xbb\xbf(\@charset "(.*?)";))/s) {
Branch: 16 branches
BranchTrueFalseTotal
if (/^(\xef\xbb\xbf(\@charset "(.*?)";)\005)/s) { } 0 22 22
elsif (/^\xef\xbb\xbf/) { } 2 20 22
elsif (/^(\@charset "(.*?)";)\005/s) { } 0 20 20
elsif (/^(\xfe\xff(\0\@\0c\0h\0a\0r\0s\0e\0t\0 \0"((?:\0.)*?)\0"\0;)\005)/s) { } 0 20 20
elsif (/^(\0\@\0c\0h\0a\0r\0s\0e\0t\0 \0"((?:\0.)*?)\0"\0;)/s) { } 1 19 20
elsif (/^(\xff\xfe(\@\0c\0h\0a\0r\0s\0e\0t\0 \0"\0((?:.\0)*?)"\0;\0))/s) { } 1 18 19
elsif (/^(\@\0c\0h\0a\0r\0s\0e\0t\0 \0"\0((?:.\0)*?)"\0;\0)/s) { } 1 17 18
elsif (/^(\0\0\xfe\xff(\0{3}\@\0{3}c\0{3}h\0{3}a\0{3}r\0{3}s\0{3}e\0{3}t \0{3}\ \0{3}"((?:\0{3}.)*?)\0{3}"\0{3};))/sx) { } 1 16 17
elsif (/^(\0{3}\@\0{3}c\0{3}h\0{3}a\0{3}r\0{3}s\0{3}e\0{3}t \0{3}\ \0{3}"((?:\0{3}.)*?)\0{3}"\0{3};)/sx) { } 1 15 16
elsif (/^(\xff\xfe\0\0(\@\0{3}c\0{3}h\0{3}a\0{3}r\0{3}s\0{3}e\0{3}t \0{3}\ \0{3}"\0{3}((?:.\0{3})*?)"\0{3};\0{3}))/sx) { } 1 14 15
elsif (/^(\@\0{3}c\0{3}h\0{3}a\0{3}r\0{3}s\0{3}e\0{3}t \0{3}\ \0{3}"\0{3}((?:.\0{3})*?)"\0{3};\0{3})/sx) { } 1 13 14
elsif (/^(?:\0\0\xfe\xff|\xff\xfe\0\0)/) { } 2 11 13
elsif (/^(?:\xfe\xff|\xff\xfe)/) { } 3 8 11
elsif (/^(\|\x83\x88\x81\x99\xa2\x85\xa3\@\x7f(.*?)\x7f\^)/s) { } 2 6 8
elsif (/^(\xae\x83\x88\x81\x99\xa2\x85\xa3\@\xfc(.*?)\xfc\^)/s) { } 1 5 6
elsif (/^(\0charset "(.*?)";)/s) { } 1 4 5
511 0 my $enc = $3;
512 0 my $dec = eval{Encode::decode($3, $1, 9)};
513 0 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 0 0 0
514 0 ▶ $dec =~ /^(\x{feff}?)$2\z/
Branch: 2 branches
BranchTrueFalseTotal
$dec =~ /^(\x{feff}?)$2\z/ and return &Encode::decode($enc, scalar($1 ? substr($_, 3) : $_)) 0 0 0
$1 ? : 0 0 0
515 and return Encode::decode($enc,
516 $1 ? substr $_, 3 : $_);
517 0 ▶ $@ = $1?"Invalid BOM for $enc: \\xef\\xbb\\xbf"
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 0 0
518 :"\"$enc\" is encoded in ASCII but is not"
519 ." ASCII-based";
520 }
521 }
522 elsif(/^\xef\xbb\xbf/) {
523 2 return Encode::decode_utf8(substr $_,3);
524 }
525 elsif(/^(\@charset "(.*?)";)/s) {
526 0 my $dec = eval{Encode::decode($2, $1, 9)};
527 0 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 0 0 0
528 0 ▶ $dec eq $1
Branch: 1 branch
BranchTrueFalseTotal
$dec eq $1 and return &Encode::decode($2, $_) 0 0 0
529 and return Encode::decode($2, $_);
530 0 $@ = "\"$2\" is encoded in ASCII but is not "
531 ."ASCII-based";
532 }
533 }
534 elsif(
535 /^(\xfe\xff(\0\@\0c\0h\0a\0r\0s\0e\0t\0 \0"((?:\0.)*?)\0"\0;))/s
536 ) {
537 0 my $enc = Encode::decode('utf16be', $3);
538 0 my $dec = eval{Encode::decode($enc, $1, 9)};
539 0 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 0 0 0
540 0 ▶ $dec =~ /^(\x{feff}?)\@charset "$enc";\z/
Branch: 2 branches
BranchTrueFalseTotal
$dec =~ /^(\x{feff}?)\@charset "$enc";\z/ and return &Encode::decode($enc, scalar($1 ? substr($_, 2) : $_)) 0 0 0
$1 ? : 0 0 0
541 and return Encode::decode($enc,
542 $1 ? substr $_, 2 : $_);
543 0 ▶ $@ = $1?"Invalid BOM for $enc: \\xfe\xff"
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 0 0
544 :"\"$enc\" is encoded in UCS-2 but is not"
545 ." UCS-2-based";
546 }
547 }
548 elsif(
549 /^(\0\@\0c\0h\0a\0r\0s\0e\0t\0 \0"((?:\0.)*?)\0"\0;)/s
550 ) {
551 1 my $origenc = my $enc = Encode::decode('utf16be', $2);
552 1 my $dec = eval{Encode::decode($enc, $1, 9)};
553 defined $dec or $dec
554 1 ▶ = eval{Encode::decode($enc.='-be', $1, 9)};
Branch: 1 branch
BranchTrueFalseTotal
defined $dec or $dec = eval { do { &Encode::decode($enc .= '-be', $1, 9) } } 0 1 1
555 1 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 1 0 1
556 1 ▶ $dec eq "\@charset \"$origenc\";"
Branch: 1 branch
BranchTrueFalseTotal
$dec eq qq[\@charset "$origenc";] and return &Encode::decode($enc, $_) 1 0 1
557 and return Encode::decode($enc, $_);
558 0 $@ ="\"$origenc\" is encoded in UCS-2 but is not "
559 ."UCS-2-based";
560 }
561 }
562 elsif(
563 /^(\xff\xfe(\@\0c\0h\0a\0r\0s\0e\0t\0 \0"\0((?:.\0)*?)"\0;\0))/s
564 ) {
565 1 my $enc = Encode::decode('utf16le', $3);
566 1 my $dec = eval{Encode::decode($enc, $1, 9)};
567 1 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 1 0 1
568 1 ▶ $dec =~ /^(\x{feff}?)\@charset "$enc";\z/
Branch: 2 branches
BranchTrueFalseTotal
$dec =~ /^(\x{feff}?)\@charset "$enc";\z/ and return &Encode::decode($enc, scalar($1 ? substr($_, 2) : $_)) 1 0 1
$1 ? : 0 1 1
569 and return Encode::decode($enc,
570 $1 ? substr $_, 2 : $_);
571 0 ▶ $@ = $1?"Invalid BOM for $enc: \\xfe\xff"
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 0 0
572 :"\"$enc\" is encoded in UCS-2-LE but is not"
573 ." UCS-2-LE-based";
574 }
575 }
576 elsif(
577 /^(\@\0c\0h\0a\0r\0s\0e\0t\0 \0"\0((?:.\0)*?)"\0;\0)/s
578 ) {
579 1 my $origenc = my $enc = Encode::decode('utf16le', $2);
580 1 my $dec = eval{Encode::decode($enc, $1, 9)};
581 !defined $dec || $dec !~ /^\@/ and $dec
582 1 ▶ = eval{Encode::decode($enc.='-le', $1, 9)};
Branch: 1 branch
BranchTrueFalseTotal
defined $dec and $dec =~ /^\@/ or $dec = eval { do { &Encode::decode($enc .= '-le', $1, 9) } } 1 0 1
Condition33%1/3
defined $dec and $dec =~ /^\@/
!ll&&!rl&&r
010
MC/DC0%0/2
defined $dec and $dec =~ /^\@/
defined $dec $dec =~ /^\@/
Truth table33%1/3
A and B
A= defined $decB= $dec =~ /^\@/
ABresult
0X0
100
111
583 1 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 1 0 1
584 1 ▶ $dec eq "\@charset \"$origenc\";"
Branch: 1 branch
BranchTrueFalseTotal
$dec eq qq[\@charset "$origenc";] and return &Encode::decode($enc, $_) 1 0 1
585 and return Encode::decode($enc, $_);
586 0 $@ ="\"$enc\" is encoded in UCS-2-LE but is not "
587 ."UCS-2-LE-based";
588 }
589 }
590 elsif(
591 /^(\0\0\xfe\xff(\0{3}\@\0{3}c\0{3}h\0{3}a\0{3}r\0{3}s\0{3}e\0{3}t
592 \0{3}\ \0{3}"((?:\0{3}.)*?)\0{3}"\0{3};))/sx
593 ) {
594 1 my $enc = Encode::decode('utf32be', $3);
595 1 my $dec = eval{Encode::decode($enc, $1, 9)};
596 1 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 1 0 1
597 1 ▶ $dec =~ /^(\x{feff}?)\@charset "$enc";\z/
Branch: 2 branches
BranchTrueFalseTotal
$dec =~ /^(\x{feff}?)\@charset "$enc";\z/ and return &Encode::decode($enc, scalar($1 ? substr($_, 2) : $_)) 1 0 1
$1 ? : 0 1 1
598 and return Encode::decode($enc,
599 $1 ? substr $_, 2 : $_);
600 0 ▶ $@ = $1?"Invalid BOM for $enc: \\xfe\xff"
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 0 0
601 :"\"$enc\" is encoded in UTF-32-BE but is not"
602 ." UTF-32-BE-based";
603 }
604 }
605 elsif(
606 /^(\0{3}\@\0{3}c\0{3}h\0{3}a\0{3}r\0{3}s\0{3}e\0{3}t
607 \0{3}\ \0{3}"((?:\0{3}.)*?)\0{3}"\0{3};)/sx
608 ) {
609 1 my $origenc = my $enc = Encode::decode('utf32be', $2);
610 1 my $dec = eval{Encode::decode($enc, $1, 9)};
611 defined $dec or $dec
612 1 ▶ = eval{Encode::decode($enc.='-be', $1, 9)};
Branch: 1 branch
BranchTrueFalseTotal
defined $dec or $dec = eval { do { &Encode::decode($enc .= '-be', $1, 9) } } 0 1 1
613 1 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 1 0 1
614 1 ▶ $dec eq "\@charset \"$origenc\";"
Branch: 1 branch
BranchTrueFalseTotal
$dec eq qq[\@charset "$origenc";] and return &Encode::decode($enc, $_) 1 0 1
615 and return Encode::decode($enc, $_);
616 0 $@ ="\"$enc\" is encoded in UTF-32-BE but is not "
617 ."UTF-32-BE-based";
618 }
619 }
620 elsif(
621 /^(\xff\xfe\0\0(\@\0{3}c\0{3}h\0{3}a\0{3}r\0{3}s\0{3}e\0{3}t
622 \0{3}\ \0{3}"\0{3}((?:.\0{3})*?)"\0{3};\0{3}))/sx
623 ) {
624 1 my $enc = Encode::decode('utf32le', $3);
625 1 my $dec = eval{Encode::decode($enc, $1, 9)};
626 1 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 1 0 1
627 1 ▶ $dec =~ /^(\x{feff}?)\@charset "$enc";\z/
Branch: 2 branches
BranchTrueFalseTotal
$dec =~ /^(\x{feff}?)\@charset "$enc";\z/ and return &Encode::decode($enc, scalar($1 ? substr($_, 2) : $_)) 1 0 1
$1 ? : 0 1 1
628 and return Encode::decode($enc,
629 $1 ? substr $_, 2 : $_);
630 0 ▶ $@ = $1?"Invalid BOM for $enc: \\xfe\xff"
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 0 0
631 :"\"$enc\" is encoded in UTF-32-LE but is not"
632 ." UTF-32-LE-based";
633 }
634 }
635 elsif(
636 /^(\@\0{3}c\0{3}h\0{3}a\0{3}r\0{3}s\0{3}e\0{3}t
637 \0{3}\ \0{3}"\0{3}((?:.\0{3})*?)"\0{3};\0{3})/sx
638 ) {
639 1 my $origenc = my $enc = Encode::decode('utf32le', $2);
640 1 my $dec = eval{Encode::decode($enc, $1, 9)};
641 !defined $dec || $dec !~ /^\@/ and $dec
642 1 ▶ = eval{Encode::decode($enc.='-le', $1, 9)};
Branch: 1 branch
BranchTrueFalseTotal
defined $dec and $dec =~ /^\@/ or $dec = eval { do { &Encode::decode($enc .= '-le', $1, 9) } } 1 0 1
Condition33%1/3
defined $dec and $dec =~ /^\@/
!ll&&!rl&&r
100
MC/DC0%0/2
defined $dec and $dec =~ /^\@/
defined $dec $dec =~ /^\@/
Truth table33%1/3
A and B
A= defined $decB= $dec =~ /^\@/
ABresult
0X0
100
111
643 1 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 1 0 1
644 1 ▶ $dec eq "\@charset \"$origenc\";"
Branch: 1 branch
BranchTrueFalseTotal
$dec eq qq[\@charset "$origenc";] and return &Encode::decode($enc, $_) 1 0 1
645 and return Encode::decode($enc, $_);
646 0 $@ ="\"$enc\" is encoded in UTF-32-LE but is not "
647 ."UTF-32-LE-based";
648 }
649 }
650 elsif(/^(?:\0\0\xfe\xff|\xff\xfe\0\0)/) {
651 2 return Encode::decode('utf32', $_);
652 }
653 elsif(/^(?:\xfe\xff|\xff\xfe)/) {
654 3 return Encode::decode('utf16', $_);
655 }
656 elsif(
657 /^(\|\x83\x88\x81\x99\xa2\x85\xa3\@\x7f(.*?)\x7f\^)/s
658 ) {
659 2 my $enc = Encode::decode('cp37', $2);
660 2 my $dec = eval{Encode::decode($enc, $1, 9)};
661 2 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 2 0 2
662 2 ▶ $dec eq "\@charset \"$enc\";"
Branch: 1 branch
BranchTrueFalseTotal
$dec eq qq[\@charset "$enc";] and return &Encode::decode($enc, $_) 2 0 2
663 and return Encode::decode($enc, $_);
664 0 $@ ="\"$enc\" is encoded in EBCDIC but is not "
665 ."EBCDIC-based";
666 }
667 }
668 elsif(
669 /^(\xae\x83\x88\x81\x99\xa2\x85\xa3\@\xfc(.*?)\xfc\^)/s
670 ) {
671 1 my $enc = Encode::decode('cp1026', $2);
672 1 my $dec = eval{Encode::decode($enc, $1, 9)};
673 1 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 1 0 1
674 1 ▶ $dec eq "\@charset \"$enc\";"
Branch: 1 branch
BranchTrueFalseTotal
$dec eq qq[\@charset "$enc";] and return &Encode::decode($enc, $_) 1 0 1
675 and return Encode::decode($enc, $_);
676 0 $@ ="\"$enc\" is encoded in IBM1026 but is not "
677 ."IBM1026-based";
678 }
679 }
680 elsif(
681 /^(\0charset "(.*?)";)/s
682 ) {
683 1 my $enc = Encode::decode('gsm0338', $2);
684 1 my $dec = eval{Encode::decode($enc, $1, 9)};
685 1 ▶ if(defined $dec) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dec) 1 0 1
686 1 ▶ $dec eq "\@charset \"$enc\";"
Branch: 1 branch
BranchTrueFalseTotal
$dec eq qq[\@charset "$enc";] and return &Encode::decode($enc, $_) 1 0 1
687 and return Encode::decode($enc, $_);
688 0 $@ ="\"$enc\" is encoded in GSM 0338 but is not "
689 ."GSM 0338-based";
690 }
691 }
692 else {
693 4 my %args = @_;
694 4 ▶ return Encode::decode($args{encoding_hint}||'utf8', $_);
Condition100%2/2
$args{'encoding_hint'} || 'utf8'
l!l
22
MC/DC100%1/1
$args{'encoding_hint'} || 'utf8'
$args{'encoding_hint'}
Truth table100%2/2
A
A= $args{'encoding_hint'}
Aresult
11
00
695 }
696 0 return;
697 }}
698  
699 22 **__END__**
700  
701 =head1 NAME
702  
703 CSS::DOM::Parser - Parser for CSS::DOM
704  
705 =head1 VERSION
706  
707 Version 0.16
708  
709 =head1 DESCRIPTION
710  
711 This is a private module (at least for now). Don't use it directly.
712  
713 =head1 SEE ALSO
714  
715 L<CSS::DOM>
« DOM/Rule/Style.pm ↑ Summary DOM/Value/Primitive.pm »