Element.pm

filter: Statementstmt 70.1% 216 / 308 Branchbran 58.0% 137 / 236 Conditioncond 43.5% 44 / 101 MC/DCmcdc 17.7% 11 / 62 Subroutinesub 72.5% 29 / 40 Podpod 17.6% 3 / 17 totaltotal 57.5% 440 / 764 CC 164 SCAR 41.9
CC
164
Cov
62%
consume
213.8
look_self
72.9
__ANON__
47.2
CRAP 65.7
↑ Summary Element/Trait.pm »
1 package HTML::Selector::Element;
2 10 our $VERSION = '0.95_03';
3  
4 ## Adapted from HTML::Selector::XPath
5 ## The parser is basically the same, the difference is in what it produces.
6  
7 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub import {
11 7 ▶ my($class) = shift;
Subroutine import: called CC=2 SCAR=7.0
12 7 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 7 0 7
13 7 require HTML::Element;
14 package # hide from pause
15 HTML::Element;
16 7 local $^W; # no warnings 'redefined' doesn't work over there in Exporter
17 7 HTML::Selector::Element::Trait->import(@_);
18 }
19 }
20
21 10 my $ident = qr/(?![0-9]|-[-0-9])[-_a-zA-Z0-9]+/;
22  
23 10 my $reg = {
24 # tag name/id/class. Caveat: no namespace
25 element => qr/^([#.]?)([^\s'"#.\/:@,=~>()\[\]|+]+)/i,
26 # attribute presence
27 attr1 => qr/^\[ \s* ($ident) \s* \]/x,
28 # attribute value match
29 attr2 => qr/^\[ \s* ($ident) \s*
30 ( [~|*^\$!]? = ) \s*
31 (?: ($ident) | "([^"]*)" | '([^']*)') \s* \] /x,
32 badattr => qr/^\[/,
33 pseudoN => qr/^:(not|has|is)\(/i, # we chop off the closing parenthesis below in the code
34 pseudo => qr/^:([()a-z0-9_+-]+)/i,
35 # adjacency/direct descendance (test for comma first)
36 combinator => qr/^\s*([>+~])\s*|^\s+/i, # doesn't capture matched whitespace
37 # rule separator
38 comma => qr/^\s*,\s*/i,
39 };
40  
41 sub new {
42 35 ▶ my($class, @expr) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
43 35 my $self = bless {}, $class;
44 35 $self->selector(@expr);
45 35 return $self;
46 }
47  
48 sub selector {
49 35 ▶ my $self = shift;
Subroutine selector: called CC=4 SCAR=14.0
Pod undocumented
50 35 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 35 0 35
51 35 delete @{$self}{qw(find is)};
52 35 $self->{selector} = join ', ', @_;
53 35 $self->{parsed} = \my @parsed;
54 35 foreach (@_) {
55 35 my($parsed, $leftover) = $self->consume($_);
56 35 ▶ length $leftover
Branch: 1 branch
BranchTrueFalseTotal
length $leftover and die "Invalid rule, couldn't parse '${leftover}'" 0 35 35
57 and die "Invalid rule, couldn't parse '$leftover'";
58 35 push @parsed, @$parsed;
59 }
60 }
61 35 return $self->{selector};
62 }
63  
64 sub convert_attribute_match {
65 20 ▶ my ($left,$op,$right) = @_;
Subroutine convert_attribute_match: called CC=7 SCAR=19.5
Pod undocumented
66 # negation (e.g. [input!="text"]) isn't implemented in CSS, but include it anyway:
67 20 ▶ if ($op eq '!=') {
Branch: 6 branches
BranchTrueFalseTotal
if ($op eq '!=') { } 1 19 20
elsif ($op eq '~=') { } 13 6 19
elsif ($op eq '*=') { } 1 5 6
elsif ($op eq '|=') { } 1 4 5
elsif ($op eq '^=') { } 1 3 4
elsif ($op eq '$=') { } 1 2 3
68 1 $left, qr/^(?!\Q$right\E$)/
69 } elsif ($op eq '~=') { # substring attribute match
70 13 $left, qr/(?<!\S)\Q$right\E(?!\S)/
71 } elsif ($op eq '*=') { # real substring attribute match
72 1 $left, qr/\Q$right\E/
73 } elsif ($op eq '|=') {
74 1 $left, qr/^\Q$right\E(?![^-])/
75 } elsif ($op eq '^=') {
76 1 $left, qr/^\Q$right\E/
77 } elsif ($op eq '$=') {
78 1 $left, qr/\Q$right\E$/
79 } else { # exact match
80 2 $left, $right
81 }
82 }
83  
84 # for our purpose, "siblings" includes the element itself
85 sub siblings {
86 66 ▶ my($this) = @_;
Subroutine siblings: called CC=2 SCAR=7.2
Pod undocumented
87 66 ▶ return children($this->{_parent}||return $this);
Condition50%1/2
$this->{'_parent'} || (return $this)
l!l
660
MC/DC0%0/1
$this->{'_parent'} || (return $this)
$this->{'_parent'}
Truth table50%1/2
A
A= $this->{'_parent'}
Aresult
11
00
88 }
89  
90 sub nth_of_type {
91 11 ▶ my($of_type, $backward, $n, $cycle) = @_;
Subroutine nth_of_type: called CC=5 SCAR=16.9
Pod undocumented
92 # nth_child = nth_of_type without type filter
93 11 ▶ $cycle ||= 0;
Condition100%2/2
$cycle ||= 0
l!l
74
MC/DC100%1/1
$cycle ||= 0
$cycle
Truth table100%2/2
A
A= $cycle
Aresult
11
00
94 11 ▶ if($n <= 0 && $cycle > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n <= 0 and $cycle > 0) 0 11 11
Condition33%1/3
$n <= 0 and $cycle > 0
!ll&&!rl&&r
1100
MC/DC0%0/2
$n <= 0 and $cycle > 0
$n <= 0 $cycle > 0
Truth table33%1/3
A and B
A= $n <= 0B= $cycle > 0
ABresult
0X0
100
111
95 # permanent correction
96 0 ▶ $n %= $cycle ||= $cycle; # first value above 0
Condition0%0/3
$cycle ||= $cycle
l!l&&r!l&&!r
000
MC/DC0%0/2
$cycle ||= $cycle
$cycle $cycle
Truth table0%0/3
A ||= B
A= $cycleB= $cycle
ABresult
1X1
011
000
97 }
98 66 ▶ return sub { my($this) = @_;
Subroutine __ANON__: called CC=9 SCAR=22.1
99 66 my @sibling = siblings($this);
100 66 ▶ @sibling = grep $_->{_tag} eq $this->{_tag}, @sibling if $of_type;
Branch: 1 branch
BranchTrueFalseTotal
if $of_type 45 21 66
101 66 ▶ for(my $n = # lexical scratch copy
Branch: 2 branches
BranchTrueFalseTotal
$n > @sibling && $cycle < 0 ? : 0 66 66
if ($n > 0 and $n <= @sibling) 142 21 163
Condition66%4/6
$n > @sibling and $cycle < 0
!ll&&!rl&&r
6600
$n > 0 and $n <= @sibling
!ll&&!rl&&r
219142
MC/DC0%0/2
$n > @sibling and $cycle < 0
$n > @sibling $cycle < 0
MC/DC100%2/2
$n > 0 and $n <= @sibling
$n > 0 $n <= @sibling
Truth table33%1/3
A and B
A= $n > @siblingB= $cycle < 0
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= $n > 0B= $n <= @sibling
ABresult
0X0
100
111
102 $n > @sibling && $cycle < 0
103 ? ($n-@sibling) % $cycle + @sibling # first value below upper bound as modulo <= 0
104 : $n ; # no correction
105 $n > 0 && $n <= @sibling; # give up as soon as we get out of range
106 $n += $cycle || last) # loop only once if $cycle is zero
107 {
108 142 ▶ return 1 if $this == $sibling[$backward ? -$n : $n - 1];
Branch: 2 branches
BranchTrueFalseTotal
if $this == $sibling[$backward ? -$n : $n - 1] 25 117 142
$backward ? : 32 110 142
Condition100%2/2
$cycle || (last)
l!l
9720
MC/DC100%1/1
$cycle || (last)
$cycle
Truth table100%2/2
A
A= $cycle
Aresult
11
00
109 }
110 41 return;
111 }
112 11 }
113  
114 sub only_child {
115 0 ▶ my($this) = @_;
Subroutine only_child: not called CC=1 SCAR=6.9
Pod undocumented
116 0 return 1 == siblings($this);
117 }
118  
119 # A hacky recursive descent
120 # Only descends for :not(...) and :has(...)
121 sub consume {
122 35 ▶ my ($self, $rule) = @_;
Subroutine consume: called CC=47 SCAR=53.7
Pod undocumented
123  
124 35 my @alt;
125 35 my $last_rule = '';
126 35 my $set = { static => my $static = [] };
127 35 my $hold; # last valid set
128 my $sibling_root; # root element of search space is sibling of start element
129 35 my($any); # flags
130 35 my $start_combinators = '';
131  
132 35 $rule =~ s/^\s+//;
133 # Loop through each "unit" of the rule
134 35 while() {
135 # Match elements
136 67 for($any = 0;; $any++) { # endless loop
137 156 ▶ if ($rule =~ s/$reg->{element}//) {
Branch: 6 branches
BranchTrueFalseTotal
if ($rule =~ s/$reg->{'element'}//) { } 70 86 156
elsif ($rule =~ s/$reg->{'attr2'}//) { } 7 79 86
elsif ($rule =~ s/$reg->{'attr1'}//) { } 1 78 79
elsif ($rule =~ /$reg->{'badattr'}/) { } 0 78 78
elsif ($rule =~ s/$reg->{'pseudoN'}//) { } 0 78 78
elsif ($rule =~ s/$reg->{'pseudo'}//) { } 11 67 78
138 70 my ($id_class,$name) = ($1,$2);
139 70 ▶ if ($id_class eq '#') { # ID
Branch: 3 branches
BranchTrueFalseTotal
if ($id_class eq '#') { } 1 69 70
elsif ($id_class eq '.') { } 12 57 69
elsif (not $set->{'tag'} and $name ne '*') { } 57 0 57
140 1 unshift @$static, id => $name;
141 # a condition very likely to fail, so try this first
142 } elsif ($id_class eq '.') { # class
143 12 push @$static, convert_attribute_match('class', '~=', $name);
144 ▶ } elsif (!$set->{tag} && $name ne '*') {
Condition33%1/3
not $set->{"tag"} and $name ne "*"
!ll&&!rl&&r
0057
MC/DC0%0/2
not $set->{"tag"} and $name ne "*"
not $set->{"tag"} $name ne "*"
Truth table33%1/3
not(A) and B
A= not $set->{"tag"}B= $name ne "*"
ABresult
0X0
100
111
145 # we're not adding '*' yet as that's a very loose condition that seldom fails
146 # It's often not even necessary to test when we have other, more stringent conditions.
147 57 $set->{tag} = $name;
148 57 push @$static, _tag => $name;
149 }
150 }
151 # Match attribute selectors
152 elsif ($rule =~ s/$reg->{attr2}//) {
153 7 push @$static, convert_attribute_match( $1, $2, $^N );
154 } elsif ($rule =~ s/$reg->{attr1}//) {
155 # any value, as long as it's defined
156 1 push @$static, convert_attribute_match( $1, '', qr// );
157 } elsif ($rule =~ $reg->{badattr}) {
158 0 Carp::croak "Invalid attribute-value selector '$rule'";
159 }
160 # Match :not and :has
161 elsif ($rule =~ s/$reg->{pseudoN}//) {
162 0 my $which = lc $1;
163 # Now we parse the rest, and after parsing the subexpression
164 # has stopped, we must find a matching closing parenthesis:
165 0 my( $subset, $leftover ) = $self->consume( $rule );
166 0 $rule = $leftover;
167 0 ▶ $rule =~ s!^\s*\)!!
Branch: 1 branch
BranchTrueFalseTotal
$rule =~ s/^\s*\)// or die "Unbalanced parentheses at '${rule}'" 0 0 0
168 or die "Unbalanced parentheses at '$rule'";
169 0 ▶ if($which eq 'not') {
Branch: 3 branches
BranchTrueFalseTotal
if ($which eq 'not') { } 0 0 0
elsif ($which eq 'is') { } 0 0 0
elsif ($which eq 'has') { } 0 0 0
170 0 my @params = criteria($subset, undef);
171 0 ▶ push @$static, sub { not look_self($_[0], @params) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
172 } elsif($which eq 'is') {
173 0 my @params = criteria($subset, undef);
174 0 ▶ push @$static, sub { look_self($_[0], @params) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
175 } elsif($which eq 'has') {
176 # This is possibly very slow, especially when executed very often, so we keep this criterium for last
177 0 push @{$set->{has}}, find_closure($subset);
178 }
179 }
180 # other pseudoclasses/pseudoelements
181 # "else" because there could be more than one :not/:has
182 elsif ($rule =~ s/$reg->{pseudo}//) {
183 11 my $simple = ":$1";
184 11 ▶ if ( my @expr = $self->parse_pseudo($1, \$rule) ) {
Branch: 6 branches
BranchTrueFalseTotal
if (my(@expr) = $self->parse_pseudo($1, \$rule)) { } 0 11 11
elsif ($1 eq 'only-child') { } 0 11 11
elsif (my(@m) = $1 =~ /^((?:first|last)-(?:child|of-type)$) | ^(nth-(?:last-)?(?:child|of-type)) \((odd|even|(\d+)|(-?\d*)n([\+\-]\d+)?)\)$/x) { } 11 0 11
elsif ($1 =~ /^contains\($/) { } 0 0 0
elsif ($1 eq 'root') { } 0 0 0
elsif ($1 eq 'empty') { } 0 0 0
185 0 push @$static, @expr;
186 } elsif ( $1 eq 'only-child') {
187 0 push @$static, only_child();
188 } elsif (my @m = $1 =~ /^((?:first|last)-(?:child|of-type)$) | ^(nth-(?:last-)?(?:child|of-type)) \((odd|even|(\d+)|(-?\d*)n([\+\-]\d+)?)\)$/x) {
189 # Matches all pseudoelements of the following lists:
190 # - first-child, last-child, first-of-type, last-of-type: without expression
191 # - nth-child, nth-of-type, nth-last-child, nth-last-of-type: with an expression between parens
192 # of one of these types: odd, even, and an+b
193 # with a lot of freedom for that last one, for example:
194 # 3, 3n, 3n+1, n+5, -n+5, -3n+5, 3n-1
195 11 my($pseudo, $nth, $expr, $n, $cycle, $offset) = @m;
196 11 ▶ if($nth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nth) { } 9 2 11
197 9 ▶ if(defined $cycle) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $cycle) { } 4 5 9
elsif (not defined $n) { } 3 2 5
198 4 ▶ $cycle .= '1' if $cycle =~ /^(-?)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $cycle =~ /^(-?)$/ 1 3 4
199 4 ▶ $n = $offset || $cycle;
Condition66%2/3
$offset || $cycle
l!l&&r!l&&!r
220
MC/DC0%0/2
$offset || $cycle
$offset $cycle
Truth table66%2/3
A || B
A= $offsetB= $cycle
ABresult
1X1
011
000
200 }
201 elsif(!defined $n) {
202 # even / odd
203 3 $cycle = 2;
204 3 ▶ $n = $expr eq 'odd' ? 1 : 2;
Branch: 1 branch
BranchTrueFalseTotal
$expr eq 'odd' ? : 1 2 3
205 }
206 9 $pseudo = $nth;
207 }
208 else {
209 # first / last
210 2 $n = 1;
211 }
212 11 my $of_type = $pseudo =~ /of-type/;
213 11 my $backward = $pseudo =~ /last/;
214 11 push @$static, nth_of_type($of_type, $backward, $n+0, $cycle);
215 } elsif ($1 =~ /^contains\($/) {
216 # not sure if this will work well in practise, in regards to whitespace
217 0 ▶ if( $rule =~ s/^\s*"([^"]*)"\s*\)// ) { # "#stupid syntax highlighter
Branch: 2 branches
BranchTrueFalseTotal
if ($rule =~ s/^\s*"([^"]*)"\s*\)//) { } 0 0 0
elsif ($rule =~ s/^\s*'([^']*)'\s*\)//) { } 0 0 0
218 0 my $fragment = $1;
219 0 ▶ push @$static, sub { $_[0]->as_text() =~ /\Q$fragment/ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
220 } elsif( $rule =~ s/^\s*'([^']*)'\s*\)// ) { #'#stupid syntax highlighter
221 0 my $fragment = $1;
222 0 ▶ push @$static, sub { $_[0]->as_text() =~ /\Q$fragment/ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
223 } else {
224 0 return( $set, $rule );
225 0 die "Malformed string in :contains(): '$rule'";
226 };
227 } elsif ( $1 eq 'root') {
228 # matches document root, or starting element
229 0 $set->{is_root} = 1;
230 } elsif ( $1 eq 'empty') {
231 0 ▶ push @$static, sub { (shift)->is_empty };
Subroutine __ANON__: not called CC=1 SCAR=6.9
232 } else {
233 0 Carp::croak "Can't translate '$1' pseudo-class";
234 }
235 }
236 else {
237 # failed to match anything
238 67 last;
239 }
240 89 $any++;
241 89 ▶ die "Endless loop?"if $any > 20000;
Branch: 1 branch
BranchTrueFalseTotal
if $any > 20000 0 89 89
242 89 undef $hold;
243 }
244  
245 # Match commas
246 67 ▶ if ($rule =~ s/$reg->{comma}//o) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rule =~ s/$reg->{'comma'}//o) { } 0 67 67
elsif ($rule =~ s/$reg->{'combinator'}//) { } 32 35 67
247 # ending one rule and beginning another
248 0 ▶ $set->{tag} ||= do { push @$static, _tag => qr/^(?!~)/; '*' };
Condition0%0/3
$set->{"tag"} ||= do { push @$static, "_tag", qr/^(?!~)/; "*" }
l!l&&r!l&&!r
000
MC/DC0%0/2
$set->{"tag"} ||= do { push @$static, "_tag", qr/^(?!~)/; "*" }
$set->{"tag"} do { push @$static, "_tag", qr/^(?!~)/; "*" }
Truth table0%0/3
A ||= B
A= $set->{"tag"}B= do { push @$static, "_tag", qr/^(?!~)/; "*" }
ABresult
1X1
011
000
249 0 ▶ $set->{sibling_root} ||= $sibling_root if $sibling_root;
Branch: 1 branch
BranchTrueFalseTotal
if $sibling_root 0 0 0
Condition0%0/3
$set->{"sibling_root"} ||= $sibling_root
l!l&&r!l&&!r
000
MC/DC0%0/2
$set->{"sibling_root"} ||= $sibling_root
$set->{"sibling_root"} $sibling_root
Truth table0%0/3
A ||= B
A= $set->{"sibling_root"}B= $sibling_root
ABresult
1X1
011
000
250 0 push @alt, $set;
251 0 $set = { static => $static = [] };
252 0 ($any, $hold, $sibling_root) = ();
253 }
254 # Match combinators (whitespace, >, + and ~)
255 elsif ($rule =~ s/$reg->{combinator}//) {
256 32 ▶ my $combinator = $1 || ' ';
Condition100%2/2
$1 || ' '
l!l
1616
MC/DC100%1/1
$1 || ' '
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
257 32 ▶ unless($any) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($any) 4 28 32
258 4 ▶ unless($set->{chained}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set->{'chained'}) { } 0 4 4
259 # rule starts with a combinator
260 # add match for start element
261 4 $set->{is_root} = 1; # root element / start element
262 } else {
263 # 2 subsequent combinators: interject a '*'
264 0 push @$static, _tag => qr/^(?!~)/;
265 0 $set->{tag} = '*';
266 }
267 }
268 # new context
269 32 ($any, $hold) = ();
270 32 ▶ $hold = $set unless $1;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 16 16 32
271 32 $set = { static => $static = [], chained => my $chained = $set, combinator => $combinator };
272 32 ▶ if($chained->{is_root} || $chained->{sibling_root}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chained->{"is_root"} or $chained->{"sibling_root"}) 4 28 32
Condition66%2/3
$chained->{"is_root"} or $chained->{"sibling_root"}
l!l&&r!l&&!r
4028
MC/DC50%1/2
$chained->{"is_root"} or $chained->{"sibling_root"}
$chained->{"is_root"} $chained->{"sibling_root"}
Truth table66%2/3
A or B
A= $chained->{"is_root"}B= $chained->{"sibling_root"}
ABresult
1X1
011
000
273 4 ▶ if($combinator =~ /([+~])/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($combinator =~ /([+~])/) 3 1 4
274 3 ▶ $set->{sibling_root} = ($chained->{sibling_root} || '') . $1;
Condition50%1/2
$chained->{'sibling_root'} || ''
l!l
03
MC/DC0%0/1
$chained->{'sibling_root'} || ''
$chained->{'sibling_root'}
Truth table50%1/2
A
A= $chained->{'sibling_root'}
Aresult
11
00
275 3 $sibling_root = $set;
276 }
277 }
278 }
279 else {
280 35 last;
281 }
282 }
283 # wrap up
284 # rule ended in whitespace - This can only happen in nested rules such as :not( ... )
285 35 ▶ $set = $hold if $hold;
Branch: 1 branch
BranchTrueFalseTotal
if $hold 0 35 35
286 35 ▶ $set->{tag} ||= do { push @$static, _tag => qr/^(?!~)/; '*' };
Condition66%2/3
$set->{"tag"} ||= do { push @$static, "_tag", qr/^(?!~)/; "*" }
l!l&&r!l&&!r
3230
MC/DC0%0/2
$set->{"tag"} ||= do { push @$static, "_tag", qr/^(?!~)/; "*" }
$set->{"tag"} do { push @$static, "_tag", qr/^(?!~)/; "*" }
Truth table66%2/3
A ||= B
A= $set->{"tag"}B= do { push @$static, "_tag", qr/^(?!~)/; "*" }
ABresult
1X1
011
000
287 35 ▶ $set->{sibling_root} ||= $sibling_root if $sibling_root;
Branch: 1 branch
BranchTrueFalseTotal
if $sibling_root 3 32 35
Condition33%1/3
$set->{"sibling_root"} ||= $sibling_root
l!l&&r!l&&!r
300
MC/DC0%0/2
$set->{"sibling_root"} ||= $sibling_root
$set->{"sibling_root"} $sibling_root
Truth table33%1/3
A ||= B
A= $set->{"sibling_root"}B= $sibling_root
ABresult
1X1
011
000
288  
289 35 push @alt, $set;
290 35 return \@alt, $rule;
291 }
292  
293 sub criteria {
294 # returns criteria for look_down, with bound closures
295 33 ▶ my($set, $refroot, $strategy) = @_;
Subroutine criteria: called CC=10 SCAR=28.8
Pod documented
296 33 ▶ $strategy ||= { banroot => 1 };
Condition50%1/2
$strategy ||= {"banroot", 1}
l!l
033
MC/DC0%0/1
$strategy ||= {"banroot", 1}
$strategy
Truth table50%1/2
A
A= $strategy
Aresult
11
00
297 33 ▶ $strategy->{banroot} = 0 if not $refroot;
Branch: 1 branch
BranchTrueFalseTotal
unless $refroot 6 27 33
298 33 my $recurse;
299 $recurse = sub {
300 # embeds $refroot
301 57 ▶ my($set, $banroot) = @_;
Subroutine __ANON__: called CC=15 SCAR=33.8
302 57 ▶ my @params = @{$set->{static}||[]};
Branch: 1 branch
BranchTrueFalseTotal
$set->{"static"} or [] 0 57 57
303  
304 57 ▶ if($set->{is_root}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set->{"is_root"}) 3 54 57
305 3 $banroot = 0;
306 3 ▶ if($refroot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($refroot) { } 3 0 3
307 # relative, top of branch
308 3 ▶ unshift @params, sub { $_[0] == $$refroot }; # unlikely to succeed, so fail fast
Subroutine __ANON__: called CC=1 SCAR=0.0
309 }
310 else {
311 # absolute, root of DOM
312 0 unshift @params, _parent => undef; # unlikely to succeed, so fail fast
313 }
314 }
315  
316 57 ▶ if($set->{chained}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($set->{'chained'}) { } 27 30 57
elsif ($banroot and not $set->{'is_root'}) { } 24 12 36
317 27 push @params, do {
318 # Value is an anonymous sub
319 # Recurse into linked list
320 27 my @params = $recurse->($set->{chained}, $banroot);
321 27 my $combinator = $set->{combinator};
322 # we're in a chained set, so we have to wrap the criteria into a test in a closure.
323 27 ▶ if ($combinator =~ /^\s+$/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($combinator =~ /^\s+$/) { } 14 13 27
elsif ($combinator =~ />/) { } 6 7 13
elsif ($combinator =~ /\+/) { } 7 0 7
elsif ($combinator =~ /\~/) { } 0 0 0
324 62 ▶ $banroot ? sub { my($this) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.1
325 62 ▶ my $rootparent = $$refroot->{_parent} || 0;
Condition100%2/2
$$refroot->{'_parent'} || 0
l!l
3230
MC/DC100%1/1
$$refroot->{'_parent'} || 0
$$refroot->{'_parent'}
Truth table100%2/2
A
A= $$refroot->{'_parent'}
Aresult
11
00
326 62 ▶ while($this = $this->{_parent} and $this != $rootparent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this = $this->{"_parent"} and $this != $rootparent) 107 5 112
Condition66%2/3
$this = $this->{"_parent"} and $this != $rootparent
!ll&&!rl&&r
50107
MC/DC50%1/2
$this = $this->{"_parent"} and $this != $rootparent
$this = $this->{"_parent"} $this != $rootparent
Truth table66%2/3
A and B
A= $this = $this->{"_parent"}B= $this != $rootparent
ABresult
0X0
100
111
327 107 ▶ look_self($this, @params)
Branch: 1 branch
BranchTrueFalseTotal
look_self($this, @params) and return 1 57 50 107
328 and return 1;
329 }
330 5 return 0;
331 }
332 0 ▶ : sub { my($this) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
333 0 ▶ while($this = $this->{_parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this = $this->{"_parent"}) 0 0 0
334 0 ▶ look_self($this, @params)
Branch: 1 branch
BranchTrueFalseTotal
look_self($this, @params) and return 1 0 0 0
335 and return 1;
336 }
337 0 return 0;
338 }
339 14 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
$banroot ? : 14 0 14
340 elsif ($combinator =~ />/) {
341 3 ▶ $banroot ? sub { my($this) = @_;
Subroutine __ANON__: called CC=5 SCAR=18.1
342 3 ▶ my $rootparent = $$refroot->{_parent} || 0;
Condition100%2/2
$$refroot->{'_parent'} || 0
l!l
12
MC/DC100%1/1
$$refroot->{'_parent'} || 0
$$refroot->{'_parent'}
Truth table100%2/2
A
A= $$refroot->{'_parent'}
Aresult
11
00
343 3 ▶ if($this = $this->{_parent} and $this != $rootparent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this = $this->{"_parent"} and $this != $rootparent) 3 0 3
Condition33%1/3
$this = $this->{"_parent"} and $this != $rootparent
!ll&&!rl&&r
003
MC/DC0%0/2
$this = $this->{"_parent"} and $this != $rootparent
$this = $this->{"_parent"} $this != $rootparent
Truth table33%1/3
A and B
A= $this = $this->{"_parent"}B= $this != $rootparent
ABresult
0X0
100
111
344 3 ▶ look_self($this, @params)
Branch: 1 branch
BranchTrueFalseTotal
look_self($this, @params) and return 1 3 0 3
345 and return 1;
346 }
347 0 return 0;
348 }
349 3 ▶ : sub { my($this) = @_;
Subroutine __ANON__: called CC=3 SCAR=12.5
350 3 ▶ if($this = $this->{_parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this = $this->{"_parent"}) 3 0 3
351 3 ▶ look_self($this, @params)
Branch: 1 branch
BranchTrueFalseTotal
look_self($this, @params) and return 1 3 0 3
352 and return 1;
353 }
354 0 return 0;
355 6 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$banroot ? : 3 3 6
356 }
357 elsif ($combinator =~ /\+/) {
358 11 ▶ sub { my($this) = @_;
Subroutine __ANON__: called CC=6 SCAR=20.2
359 11 my @left = $this->left;
360 11 ▶ while(@left) {
Branch: 1 branch
BranchTrueFalseTotal
if (@left) 7 4 11
361 7 $this = pop @left;
362 7 ▶ ref $this && $this->{_tag} && $this->{_tag} !~ /^~/ or next;
Branch: 1 branch
BranchTrueFalseTotal
ref $this and $this->{"_tag"} and not $this->{"_tag"} =~ /^~/ or next 0 7 7
Condition33%2/6
ref $this and $this->{"_tag"} and not $this->{"_tag"} =~ /^~/
!ll&&!rl&&r
007
ref $this and $this->{"_tag"}
!ll&&!rl&&r
007
MC/DC0%0/3
ref $this and $this->{"_tag"} and not $this->{"_tag"} =~ /^~/
ref $this $this->{"_tag"} not $this->{"_tag"} =~ /^~/
Truth table25%1/4
A and B and not(C)
A= ref $thisB= $this->{"_tag"}C= not $this->{"_tag"} =~ /^~/
ABCresult
0XX0
10X0
1100
1111
363 7 ▶ look_self($this, @params)
Branch: 1 branch
BranchTrueFalseTotal
look_self($this, @params) and return 1 7 0 7
364 and return 1;
365 0 return 0;
366 }
367 4 return 0;
368 7 };
369 }
370 elsif ($combinator =~ /\~/) {
371 0 ▶ sub { my($this) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
372 0 my @left = $this->left;
373 0 ▶ while(@left) {
Branch: 1 branch
BranchTrueFalseTotal
if (@left) 0 0 0
374 0 $this = pop @left;
375 0 ▶ ref $this && $this->{_tag} !~ /^~/ or next;
Branch: 1 branch
BranchTrueFalseTotal
ref $this and not $this->{"_tag"} =~ /^~/ or next 0 0 0
Condition0%0/3
ref $this and not $this->{"_tag"} =~ /^~/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $this and not $this->{"_tag"} =~ /^~/
ref $this not $this->{"_tag"} =~ /^~/
Truth table0%0/3
A and not(B)
A= ref $thisB= not $this->{"_tag"} =~ /^~/
ABresult
0X0
100
111
376 0 ▶ look_self($this, @params)
Branch: 1 branch
BranchTrueFalseTotal
look_self($this, @params) and return 1 0 0 0
377 and return 1;
378 }
379 0 return 0;
380 }
381 0 }
382 else {
383 0 die "Weird combinator '$combinator'"
384 }
385 };
386 }
387 ▶ elsif($banroot && !$set->{is_root}) {
Condition66%2/3
$banroot and not $set->{"is_root"}
!ll&&!rl&&r
6024
MC/DC50%1/2
$banroot and not $set->{"is_root"}
$banroot not $set->{"is_root"}
Truth table66%2/3
A and not(B)
A= $banrootB= not $set->{"is_root"}
ABresult
0X0
100
111
388 # if :root was not specified, $root should never match
389 24 ▶ push @params, sub { $_[0] != $$refroot }; # likely to succeed, so fail late
Subroutine __ANON__: called CC=1 SCAR=0.0
390 }
391  
392 # do the :has tests last, because it's a complete subtree scan and that may be very slow.
393 57 ▶ push @params, @{$set->{has}} if $set->{has};
Branch: 1 branch
BranchTrueFalseTotal
if $set->{"has"} 0 57 57
394 57 ▶ return wantarray ? @params : \@params;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 57 0 57
395 33 };
396  
397  
398 33 ▶ if(ref $set eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $set eq "ARRAY") 30 3 33
399 30 ▶ if(@$set > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$set > 1) 0 30 30
400 0 my %tags;
401 0 ▶ my @alt = map { $tags{$_->{tag}||'*'} = 1; [ $recurse->($_, !$refroot) ] } @$set;
Condition0%0/2
$_->{'tag'} || '*'
l!l
00
MC/DC0%0/1
$_->{'tag'} || '*'
$_->{'tag'}
Truth table0%0/2
A
A= $_->{'tag'}
Aresult
11
00
402 0 ▶ my @params = sub { my($this) = @_; look_self($this, @$_) and return 1 foreach @alt; return 0 };;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
look_self($this, @$_) and return 1 0 0 0
403 0 ▶ unshift @params, sub { $tags{(shift)->{_tag}} } unless $tags{'*'};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless $tags{"*"} 0 0 0
404 0 ▶ return wantarray ? @params : \@params;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
405 }
406 30 ($set) = @$set; # non-destructive
407 }
408 33 ▶ if(ref $set eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $set eq 'HASH') { } 30 3 33
elsif (ref $set) { } 3 0 3
409 30 return $recurse->($set, $refroot);
410 }
411 elsif(ref $set) {
412 # assumed method call
413 3 return criteria($set->{parsed}, $refroot);
414 }
415 }
416  
417 ▶sub parse_pseudo {
Subroutine parse_pseudo: called CC=1 SCAR=0.0
Pod undocumented
418 # nop, for subclassing
419 }
420  
421 sub find_closure {
422 26 ▶ my $sets = shift;
Subroutine find_closure: called CC=8 SCAR=25.2
Pod undocumented
423 26 ▶ $sets = $sets->{parsed} if ref $sets ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $sets ne "ARRAY" 0 26 26
424 26 my $root; # The embedded variable
425 26 my(@down, @via_right, $right_down, @right_filter);
426 26 foreach my $set (@$sets) {
427 26 ▶ unless($set->{sibling_root}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($set->{'sibling_root'}) { } 1 25 26
if (do { ref $set->{'sibling_root'} }) { } 0 1 1
428 25 push @down, $set;
429 }
430 elsif(ref $set->{sibling_root}) {
431 0 push @via_right, $set;
432 0 push @right_filter, $set->{sibling_root};
433 0 $right_down = 1;
434 }
435 else {
436 1 push @via_right, $set;
437 1 push @right_filter, $set;
438 }
439 }
440 26 foreach my $array(\@down, \@via_right, \@right_filter) {
441 78 ▶ @$array = criteria($array, \$root) if @$array;
Branch: 1 branch
BranchTrueFalseTotal
if @$array 27 51 78
442 }
443 26 ▶ unless(@via_right) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via_right) { } 1 25 26
444 # the most common case: down only
445 return sub {
446 25 ▶ $root = shift; return $root->look_down(@down)
Subroutine __ANON__: called CC=1 SCAR=0.0
447 25 };
448 }
449 else {
450 return sub {
451 2 ▶ $root = shift;
Subroutine __ANON__: called CC=12 SCAR=38.5
452 2 my($result, @result);
453 2 ▶ if(@down) {
Branch: 1 branch
BranchTrueFalseTotal
if (@down) 0 2 2
454 # unlikely, but possible
455 0 ▶ unless(wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
456 0 ▶ $result = $root->look_down(@down) and return $result;
Branch: 1 branch
BranchTrueFalseTotal
$result = $root->look_down(@down) and return $result 0 0 0
457 }
458 else {
459 0 @result = $root->look_down(@down);
460 }
461 }
462 2 ▶ if(my @right = grep { ref and look_self($_, @right_filter) } $root->right) {
Branch: 2 branches
BranchTrueFalseTotal
if (my(@right) = grep({ref $_ and look_self($_, @right_filter);} $root->right)) 2 0 2
ref $_ and look_self($_, @right_filter) 2 0 2
463 2 ▶ unless($right_down) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($right_down) 2 0 2
464 2 ▶ return wantarray ? (@result, @right) : shift @right;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
465 }
466 0 ▶ unless(wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
467 0 ▶ $result = $_->look_down(@via_right) and return $result foreach @right;
Branch: 1 branch
BranchTrueFalseTotal
$result = $_->look_down(@via_right) and return $result 0 0 0
468 }
469 else {
470 0 push @result, $_->look_down(@via_right) foreach @right;
471 }
472 }
473 0 return @result;
474 1 };
475 }
476 }
477  
478 # flipped
479 sub find {
480 27 ▶ my($self, $element) = @_;
Subroutine find: called CC=2 SCAR=7.1
Pod documented
481 27 ▶ return ($self->{find} ||= find_closure($self->{parsed}))->($element)
Condition66%2/3
$self->{"find"} ||= find_closure($self->{"parsed"})
l!l&&r!l&&!r
1260
MC/DC0%0/2
$self->{"find"} ||= find_closure($self->{"parsed"})
$self->{"find"} find_closure($self->{"parsed"})
Truth table66%2/3
A ||= B
A= $self->{"find"}B= find_closure($self->{"parsed"})
ABresult
1X1
011
000
482 }
483  
484 package HTML::Selector::Element::Trait;
485 # core methods for trait that adds or overrides Selector support in HTML::Element
486 # use as a superclass in a subclass of HTML::Element, putting it before HTML::Element in @ISA
487 # or monkeypatch HTML::Element: import it into the HTML::Element package
488  
489 10 require Carp;
490  
491 10 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
492 10 our @EXPORT = qw(&find is closest);
493 10 our @EXPORT_OK = qw(look_self siblings children &select &query);
494  
495 sub children { # child elements, no fake elements
496 66 ▶ my($this) = @_;
Subroutine children: called CC=4 SCAR=15.6
Pod undocumented
497 66 ▶ return grep { ref and $_->{_tag} and $_->{_tag} !~ /^~/ } @{$this->{_content}||return};
Branch: 2 branches
BranchTrueFalseTotal
ref $_ and $_->{"_tag"} and not $_->{"_tag"} =~ /^~/ 462 0 462
$this->{"_content"} or return 0 66 66
Condition33%1/3
ref $_ and $_->{"_tag"}
!ll&&!rl&&r
00462
MC/DC0%0/2
ref $_ and $_->{"_tag"}
ref $_ $_->{"_tag"}
Truth table33%1/3
A and B
A= ref $_B= $_->{"_tag"}
ABresult
0X0
100
111
498 }
499  
500 sub look_self {
501 123 ▶ my $this = shift;
Subroutine look_self: called CC=19 SCAR=42.9
Pod undocumented
502 123 my($attr, $value, $matcher);
503 123 ▶ while(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 195 73 268
504 # For speed reasons, no nested scopes and no block scope lexical variables
505 ref ($attr = shift) or
506 195 ▶ 2 != (defined($matcher = shift) + defined($value = $this->{$attr}) || next) ? return
Branch: 7 branches
BranchTrueFalseTotal
ref($attr = shift()) or 2 != (defined($matcher = shift()) + defined($value = $this->{$attr}) || (next)) ? return : (ref $value ? ref $matcher eq ref $value && $matcher eq $value ? next : (return) : (ref $matcher ? ref $matcher eq "Regexp" && $value =~ /$matcher/ ? next : (return) : ($value eq $matcher ? next : (return)))) 125 70 195
2 != (defined($matcher = shift()) + defined($value = $this->{$attr}) || (next)) ? : 13 112 125
ref $value ? : 0 112 112
ref $matcher eq ref $value && $matcher eq $value ? : 0 0 0
ref $matcher ? : 67 45 112
ref $matcher eq 'Regexp' && $value =~ /$matcher/ ? : 30 37 67
$value eq $matcher ? : 45 0 45
Condition37%3/8
defined($matcher = shift()) + defined($value = $this->{$attr}) || (next)
l!l
1250
ref $matcher eq ref $value and $matcher eq $value
!ll&&!rl&&r
000
ref $matcher eq "Regexp" and $value =~ /$matcher/
!ll&&!rl&&r
03730
MC/DC0%0/1
defined($matcher = shift()) + defined($value = $this->{$attr}) || (next)
defined($matcher = shift()) + defined($value = $this->{$attr})
MC/DC0%0/2
ref $matcher eq ref $value and $matcher eq $value
ref $matcher eq ref $value $matcher eq $value
MC/DC50%1/2
ref $matcher eq "Regexp" and $value =~ /$matcher/
ref $matcher eq "Regexp" $value =~ /$matcher/
Truth table50%1/2
A
A= defined($matcher = shift()) + defined($value = $this->{$attr})
Aresult
11
00
Truth table0%0/3
A and B
A= ref $matcher eq ref $valueB= $matcher eq $value
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= ref $matcher eq "Regexp"B= $value =~ /$matcher/
ABresult
0X0
100
111
507 : ref $value ? # identical class and stringification or fail
508 ref $matcher eq ref $value && $matcher eq $value ? next : return
509 : ref $matcher
510 ? ref $matcher eq 'Regexp' && $value =~ $matcher ? next : return
511 : $value eq $matcher ? next : return;
512 70 ▶ ref $attr eq 'CODE' and $attr->($this) ? next : return;
Branch: 2 branches
BranchTrueFalseTotal
ref $attr eq "CODE" and &$attr($this) ? next : (return) 70 0 70
&$attr($this) ? : 70 0 70
513 # standard processing ends here
514 0 ▶ if(ref $attr eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr eq "ARRAY") 0 0 0
515 0 my $success;
516 0 foreach my $rule (@$attr) {
517 0 ▶ next if ref $rule ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $rule ne "ARRAY" 0 0 0
518 0 ▶ $success = look_self($this, @$rule) and last;
Branch: 1 branch
BranchTrueFalseTotal
$success = look_self($this, @$rule) and last 0 0 0
519 }
520 0 ▶ $success and next;
Branch: 1 branch
BranchTrueFalseTotal
$success and next 0 0 0
521 }
522 # unknown doesn't match
523 0 return;
524 }
525 73 return $this; # matches
526 }
527  
528 10 my %store;
529 sub find {
530 # backward compatible with find_by_tag_name in HTMl::Element if you stick to normal tags
531 # If you do need special tags (= starting with "~"), find_by_tag_name is still available, and faster than look_down anyway
532 23 ▶ my($element) = shift;
Subroutine find: called CC=2 SCAR=7.6
Pod undocumented
533 23 ▶ my $selector = $store{join ', ', @_} ||= HTML::Selector::Element->new(@_);
Condition33%1/3
$store{join ", ", @_} ||= "HTML::Selector::Element"->new(@_)
l!l&&r!l&&!r
0230
MC/DC0%0/2
$store{join ", ", @_} ||= "HTML::Selector::Element"->new(@_)
$store{join ", ", @_} "HTML::Selector::Element"->new(@_)
Truth table33%1/3
A ||= B
A= $store{join ", ", @_}B= "HTML::Selector::Element"->new(@_)
ABresult
1X1
011
000
534 23 return $selector->find($element);
535 }
536  
537 sub is {
538 1 ▶ my($element) = shift;
Subroutine is: called CC=4 SCAR=15.0
Pod undocumented
539 1 ▶ @_ or return;
Branch: 1 branch
BranchTrueFalseTotal
@_ or return 0 1 1
540 1 ▶ my $selector = $store{join ', ', @_} ||= HTML::Selector::Element->new(@_);
Condition33%1/3
$store{join ", ", @_} ||= "HTML::Selector::Element"->new(@_)
l!l&&r!l&&!r
010
MC/DC0%0/2
$store{join ", ", @_} ||= "HTML::Selector::Element"->new(@_)
$store{join ", ", @_} "HTML::Selector::Element"->new(@_)
Truth table33%1/3
A ||= B
A= $store{join ", ", @_}B= "HTML::Selector::Element"->new(@_)
ABresult
1X1
011
000
541 1 ▶ $selector->{is} ||= [$selector->criteria];
Condition50%1/2
$selector->{"is"} ||= [$selector->criteria]
l!l
01
MC/DC0%0/1
$selector->{"is"} ||= [$selector->criteria]
$selector->{"is"}
Truth table50%1/2
A
A= $selector->{"is"}
Aresult
11
00
542 1 return look_self($element, @{$selector->{is}});
543 }
544  
545 sub closest {
546 0 ▶ my($element) = shift;
Subroutine closest: not called CC=3 SCAR=24.8
Pod undocumented
547 0 ▶ my $selector = $store{join ', ', @_} ||= HTML::Selector::Element->new(@_);
Condition0%0/3
$store{join ", ", @_} ||= "HTML::Selector::Element"->new(@_)
l!l&&r!l&&!r
000
MC/DC0%0/2
$store{join ", ", @_} ||= "HTML::Selector::Element"->new(@_)
$store{join ", ", @_} "HTML::Selector::Element"->new(@_)
Truth table0%0/3
A ||= B
A= $store{join ", ", @_}B= "HTML::Selector::Element"->new(@_)
ABresult
1X1
011
000
548 0 ▶ $selector->{is} ||= [$selector->criteria];
Condition0%0/2
$selector->{"is"} ||= [$selector->criteria]
l!l
00
MC/DC0%0/1
$selector->{"is"} ||= [$selector->criteria]
$selector->{"is"}
Truth table0%0/2
A
A= $selector->{"is"}
Aresult
11
00
549 0 return $element->look_up(@{$selector->{is}});
550 }
551  
552 sub select {
553 # same as find except the criteria are absolute in the DOM, instead of relative to the start element
554 # only searches down, never below siblings
555 2 ▶ my($element) = shift;
Subroutine select: called CC=3 SCAR=11.8
Pod undocumented
556 2 ▶ my $selector = $store{join ', ', @_} ||= HTML::Selector::Element->new(@_);
Condition33%1/3
$store{join ", ", @_} ||= "HTML::Selector::Element"->new(@_)
l!l&&r!l&&!r
020
MC/DC0%0/2
$store{join ", ", @_} ||= "HTML::Selector::Element"->new(@_)
$store{join ", ", @_} "HTML::Selector::Element"->new(@_)
Truth table33%1/3
A ||= B
A= $store{join ", ", @_}B= "HTML::Selector::Element"->new(@_)
ABresult
1X1
011
000
557 2 ▶ $selector->{is} ||= [$selector->criteria];
Condition50%1/2
$selector->{"is"} ||= [$selector->criteria]
l!l
02
MC/DC0%0/1
$selector->{"is"} ||= [$selector->criteria]
$selector->{"is"}
Truth table50%1/2
A
A= $selector->{"is"}
Aresult
11
00
558 2 return $element->look_down(@{$selector->{is}});
559 }
560  
561 # alias
562 10 *query = \&select;
563  
564 package HTML::Selector::Element;
565 # round up: import subs from Trait
566  
567 10 HTML::Selector::Element::Trait->import(qw(look_self children));
568  
569 10 1;
↑ Summary Element/Trait.pm »