| 1 | package Mojo::DOM58::_CSS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # This file is part of Mojo::DOM58 which is released under: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # The Artistic License 2.0 (GPL Compatible) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # See the documentation for Mojo::DOM58 for full license details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Data::Dumper (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use constant DEBUG => $ENV{MOJO_DOM58_CSS_DEBUG} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{'MOJO_DOM58_CSS_DEBUG'} || 0
MC/DC0%0/1
$ENV{'MOJO_DOM58_CSS_DEBUG'} || 0
$ENV{'MOJO_DOM58_CSS_DEBUG'}
Truth table50%1/2
A
A= $ENV{'MOJO_DOM58_CSS_DEBUG'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our $VERSION = '3.003'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | my $ESCAPE_RE = qr/\\[^0-9a-fA-F]|\\[0-9a-fA-F]{1,6}/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my $ATTR_RE = qr/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | \[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ((?:$ESCAPE_RE|[\w\-])+) # Key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | (\W)?= # Operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | (?:"((?:\\"|[^"])*)"|'((?:\\'|[^'])*)'|([^\]]+?)) # Value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | (?:\s+(?:(i|I)|s|S))? # Case-sensitivity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | \] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | /x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1208 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1208 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1208 | ▶ | sub tree { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tree: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1208 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1208 | ▶ | return $self->{tree} unless @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $self->{tree} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 51 | ▶ | sub matches { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
matches: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 51 | my $tree = shift->tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 51 | ▶ | return undef if $tree->[0] ne 'tag'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 49 | return _match(_compile(@_), $tree, $tree, _root($tree)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 445 | ▶ | sub select { _select(0, shift->tree, _compile(@_)) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 712 | ▶ | sub select_one { _select(1, shift->tree, _compile(@_)) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select_one: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 45 | ▶ | sub _absolutize { [map { _is_scoped($_) ? $_ : [[['pc', 'scope']], ' ', @$_] } @{shift()}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_absolutize: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1761 | ▶ | sub _all_tags { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_all_tags: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1761 | my $tree = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1761 | my @tags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1761 | ▶ | my @queue = @$tree[($tree->[0] eq 'root' ? 1 : 4) .. $#$tree]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1761 | ▶ | while (my $current = shift @queue) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 136372 | ▶ | next unless $current->[0] eq 'tag'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 45941 | push @tags, $current; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 45941 | unshift @queue, @$current[4 .. $#$current]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1761 | return \@tags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1645 | ▶ | sub _attr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attr: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1645 | my ($name, $value_re, $current) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1645 | my $attrs = $current->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1645 | ▶ | return undef unless exists $attrs->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 654 | my $value = $attrs->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 654 | ▶ | return undef if !defined $value && defined $value_re; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value and defined $value_re
MC/DC100%2/2
not defined $value and defined $value_re
not defined $value
defined $value_re
Truth table100%3/3
not(A) and B
A= not defined $valueB= defined $value_re
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 653 | ▶ | return 1 if !defined $value_re || $value =~ $value_re; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value_re or $value =~ /$value_re/
MC/DC100%2/2
not defined $value_re or $value =~ /$value_re/
not defined $value_re
$value =~ /$value_re/
Truth table100%3/3
not(A) or B
A= not defined $value_reB= $value =~ /$value_re/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 246 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1262 | ▶ | sub _compile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compile: called CC=33 SCAR=35.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1262 | my ($css, %ns) = ('' . shift, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1262 | $css =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1262 | $css =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1262 | my $group = [[]]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1262 | ▶ | while (my $selectors = $group->[-1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 4392 | ▶ | push @$selectors, [] unless @$selectors && ref $selectors->[-1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$selectors and ref $selectors->[-1]
MC/DC100%2/2
@$selectors and ref $selectors->[-1]
@$selectors
ref $selectors->[-1]
Truth table100%3/3
A and B
A= @$selectorsB= ref $selectors->[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 4392 | my $last = $selectors->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Separator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 4392 | ▶ | if ($css =~ /\G\s*,\s*/gc) { push @$group, [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # Combinator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | elsif ($css =~ /\G\s*([>+~])\s*/gc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 485 | ▶ | push @$last, ['pc', 'scope'] unless @$last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 485 | push @$selectors, $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # Descendent combinator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | elsif ($css =~ /\G\s+/gc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 262 | ▶ | push @$last, ['pc', 'scope'] unless @$last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 262 | push @$selectors, ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # Class or ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | elsif ($css =~ /\G([.#])((?:$ESCAPE_RE\s?|[^,.#:[\s>~+])+)/gco) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 160 | ▶ | my ($name, $op) = $1 eq '.' ? ('class', '~') : ('id', ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 160 | push @$last, ['attr', $name, _value($op, $2)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # Attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | elsif ($css =~ /\G$ATTR_RE/gco) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 250 | ▶ | push @$last, [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 'attr', _unescape($1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | _value( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | defined($2) ? $2 : '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | defined($3) ? $3 : defined($4) ? $4 : $5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | $6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Pseudo-class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | elsif ($css =~ /\G:([\w\-]+)(?:\(((?:\([^)]+\)|[^)])+)\))?/gcs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 299 | my ($name, $args) = (lc $1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # ":text" (raw text) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 299 | ▶ | $args = [$args =~ m!^/(.+)/$! ? qr/$1/ : qr/\Q$args\E/i] if $name eq 'text'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # ":is" and ":not" (contains more selectors) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 299 | ▶ | $args = _compile($args, %ns) if $name eq 'has' || $name eq 'is' || $name eq 'not'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$name eq "has" or $name eq "is" or $name eq "not"
$name eq "has" or $name eq "is"
MC/DC100%3/3
$name eq "has" or $name eq "is" or $name eq "not"
$name eq "has"
$name eq "is"
$name eq "not"
Truth table100%4/4
A or B or C
A= $name eq "has"B= $name eq "is"C= $name eq "not"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # ":nth-*" (with An+B notation) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 299 | ▶ | $args = _equation($args) if $name =~ /^nth-/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # ":first-*", ":last-*" (rewrite to ":nth-(last-)*") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 299 | ▶ | ($name, $args) = ("nth-$+", [0, 1]) if $name =~ /^(?:first-(.+)|(last-.+))$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 299 | push @$last, ['pc', $name, $args]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # Tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | elsif ($css =~ /\G((?:$ESCAPE_RE\s|\\[\s\S]|[^,.#:[\s>~+])+)/gco) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1658 | ▶ | my $alias = (my $name = $1) =~ s/^([^|]*)\|// && $1 ne '*' ? $1 : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
(my $name = $1) =~ s/^([^|]*)\|// and $1 ne "*"
MC/DC100%2/2
(my $name = $1) =~ s/^([^|]*)\|// and $1 ne "*"
(my $name = $1) =~ s/^([^|]*)\|//
$1 ne "*"
Truth table100%3/3
A and B
A= (my $name = $1) =~ s/^([^|]*)\|//B= $1 ne "*"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1658 | ▶ | return [['invalid']] if defined $alias && length $alias && !defined $ns{$alias}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $alias and length $alias and not defined $ns{$alias}
defined $alias and length $alias
MC/DC100%3/3
defined $alias and length $alias and not defined $ns{$alias}
defined $alias
length $alias
not defined $ns{$alias}
Truth table100%4/4
A and B and not(C)
A= defined $aliasB= length $aliasC= not defined $ns{$alias}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1657 | ▶ | my $ns = defined $alias && length $alias ? $ns{$alias} : $alias; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $alias and length $alias
MC/DC100%2/2
defined $alias and length $alias
defined $alias
length $alias
Truth table100%3/3
A and B
A= defined $aliasB= length $alias
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1657 | ▶ | push @$last, ['tag', $name eq '*' ? undef : _name($name), _unescape($ns)]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1261 | ▶ | else { pos $css < length $css ? croak "Unknown CSS selector: $css" : last } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1259 | warn qq{-- CSS Selector ($css)\n@{[_dumper($group)]}} if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1259 | return $group; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub _dumper { Data::Dumper->new([@_])->Indent(1)->Sortkeys(1)->Terse(1)->Useqq(1)->Dump } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dumper: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 117 | ▶ | sub _equation { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_equation: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 117 | ▶ | return [0, 0] unless my $equation = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # "even" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 115 | ▶ | return [2, 0] if $equation =~ /^\s*even\s*$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # "odd" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 106 | ▶ | return [2, 1] if $equation =~ /^\s*odd\s*$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # "4", "+4" or "-4" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 94 | ▶ | return [0, $1] if $equation =~ /^\s*((?:\+|-)?\d+)\s*$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # "n", "4n", "+4n", "-4n", "n+1", "4n-1", "+4n-1" (and other variations) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 52 | ▶ | return [0, 0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | unless $equation =~ /^\s*((?:\+|-)?(?:\d+)?)?n\s*((?:\+|-)\s*\d+)?\s*$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 51 | ▶ | return [$1 eq '-' ? -1 : !length $1 ? 1 : $1, join('', split(' ', $2 || 0))]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
$2 || 0
MC/DC100%1/1
$2 || 0
$2
Truth table100%2/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 677 | ▶ | sub _evaluate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_evaluate: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 677 | my ($group, $tree, $scope, $pool) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 677 | my (@results, %seen); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 677 | push @results, grep { !$seen{$_}++ } _evaluate_one($_, $tree, $scope, $pool) for @$group; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 677 | return \@results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 688 | ▶ | sub _evaluate_one { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_evaluate_one: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 688 | my ($selector, $tree, $scope, $pool) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # Match the leftmost compound, then propagate forward through combinators | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 688 | my @parts = @$selector; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 688 | my $compound = shift @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 688 | ▶ | return () unless ref $compound; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 687 | my @candidates = grep { _selector($compound, $_, $tree, $scope) } @$pool; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 687 | ▶ | while (@parts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 750 | my $combinator = shift @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 750 | my $next = shift @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 750 | ▶ | return () unless ref $next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 750 | my (%seen, @new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 750 | for my $node (@candidates) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1729 | for my $cand (_step_forward($combinator, $node)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 40998 | ▶ | next if $seen{$cand}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 3349 | ▶ | push @new, $cand if _selector($next, $cand, $tree, $scope); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 750 | @candidates = @new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 687 | return @candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1302 | ▶ | sub _is_scoped { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_scoped: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1302 | my $selector = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1302 | ▶ | for my $pc (grep { $_->[0] eq 'pc' } map { ref $_ ? @$_ : () } @$selector) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # Selector with ":scope" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 361 | ▶ | return 1 if $pc->[1] eq 'scope'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # Argument of functional pseudo-class with ":scope" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 271 | ▶ | return 1 if ($pc->[1] eq 'has' || $pc->[1] eq 'is' || $pc->[1] eq 'not') && grep { _is_scoped($_) } @{$pc->[2]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$pc->[1] eq "has" || $pc->[1] eq "is" || $pc->[1] eq "not" and grep {_is_scoped($_);} @{$$pc[2];}
$pc->[1] eq "has" or $pc->[1] eq "is" or $pc->[1] eq "not"
$pc->[1] eq "has" or $pc->[1] eq "is"
MC/DC100%4/4
$pc->[1] eq "has" || $pc->[1] eq "is" || $pc->[1] eq "not" and grep {_is_scoped($_);} @{$$pc[2];}
$pc->[1] eq "has"
$pc->[1] eq "is"
$pc->[1] eq "not"
grep {_is_scoped($_);} @{$$pc[2];}
Truth table100%7/7
A or B or C and D
A= $pc->[1] eq "has"B= $pc->[1] eq "is"C= $pc->[1] eq "not"D= grep {_is_scoped($_);} @{$$pc[2];}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1202 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 157 | ▶ | sub _match { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_match: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 157 | my ($group, $current, $tree, $scope) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 157 | ▶ | _match_one($_, $current, $tree, $scope) and return 1 for @$group; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 93 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 167 | ▶ | sub _match_one { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_match_one: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 167 | my ($selector, $current, $tree, $scope) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # Match the rightmost compound, then propagate backward through combinators | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 167 | my @parts = reverse @$selector; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 167 | my $compound = shift @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 167 | ▶ | return undef unless ref $compound && _selector($compound, $current, $tree, $scope); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $compound and _selector($compound, $current, $tree, $scope)
MC/DC50%1/2
ref $compound and _selector($compound, $current, $tree, $scope)
ref $compound
_selector($compound, $current, $tree, $scope)
Truth table66%2/3
A and B
A= ref $compoundB= _selector($compound, $current, $tree, $scope)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 66 | my @candidates = ($current); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 66 | ▶ | while (@parts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 6 | my $combinator = shift @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 6 | my $next = shift @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 6 | ▶ | return undef unless ref $next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 6 | my (%seen, @new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 6 | for my $node (@candidates) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 6 | for my $cand (_step_back($combinator, $node, $scope)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 9 | ▶ | next if $seen{$cand}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 9 | ▶ | push @new, $cand if _selector($next, $cand, $tree, $scope); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 6 | ▶ | return undef unless @new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | @candidates = @new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 64 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1612 | ▶ | sub _name {qr/(?:^|:)\Q@{[_unescape(shift)]}\E$/} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 77 | ▶ | sub _namespace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_namespace: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 77 | my ($ns, $current) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 77 | ▶ | my $attr = $current->[1] =~ /^([^:]+):/ ? "xmlns:$1" : 'xmlns'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 77 | ▶ | while ($current) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 119 | ▶ | last if $current->[0] eq 'root'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 115 | ▶ | return $current->[2]{$attr} eq $ns if exists $current->[2]{$attr}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 42 | $current = $current->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # Failing to match yields true if searching for no namespace, false otherwise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 4 | return !length $ns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1836 | ▶ | sub _pc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pc: called CC=35 SCAR=35.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1836 | my ($class, $args, $current, $tree, $scope) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # ":scope" (root can only be a :scope) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1836 | ▶ | return $current eq $scope if $class eq 'scope'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1342 | ▶ | return undef if $current->[0] eq 'root'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # ":checked" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | return exists $current->[2]{checked} || exists $current->[2]{selected} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1316 | ▶ | if $class eq 'checked'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $current->[2]{'checked'} || exists $current->[2]{'selected'}
MC/DC100%2/2
exists $current->[2]{'checked'} || exists $current->[2]{'selected'}
exists $current->[2]{'checked'}
exists $current->[2]{'selected'}
Truth table100%3/3
A || B
A= exists $current->[2]{'checked'}B= exists $current->[2]{'selected'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # ":not" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1121 | ▶ | return !_match($args, $current, $current, $scope) if $class eq 'not'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # ":is" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 1026 | ▶ | return !!_match($args, $current, $current, $scope) if $class eq 'is'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # ":has" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1013 | ▶ | return !!_select(1, $current, $args) if $class eq 'has'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # ":empty" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 994 | ▶ | return !grep { !($_->[0] eq 'comment' || $_->[0] eq 'pi') } @$current[4 .. $#$current] if $class eq 'empty'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_->[0] eq 'comment' || $_->[0] eq 'pi'
MC/DC100%2/2
$_->[0] eq 'comment' || $_->[0] eq 'pi'
$_->[0] eq 'comment'
$_->[0] eq 'pi'
Truth table100%3/3
A || B
A= $_->[0] eq 'comment'B= $_->[0] eq 'pi'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # ":root" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 966 | ▶ | return $current->[3] && $current->[3][0] eq 'root' if $class eq 'root'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$current->[3] && $current->[3][0] eq 'root'
MC/DC50%1/2
$current->[3] && $current->[3][0] eq 'root'
$current->[3]
$current->[3][0] eq 'root'
Truth table66%2/3
A && B
A= $current->[3]B= $current->[3][0] eq 'root'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # ":text" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 914 | ▶ | return grep { ($_->[0] eq 'text' || $_->[0] eq 'raw') && $_->[1] =~ $args->[0] } @$current[4 .. $#$current] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
($_->[0] eq 'text' || $_->[0] eq 'raw') && $_->[1] =~ /$args->[0]/
$_->[0] eq "text" or $_->[0] eq "raw"
MC/DC66%2/3
($_->[0] eq 'text' || $_->[0] eq 'raw') && $_->[1] =~ /$args->[0]/
$_->[0] eq "text"
$_->[0] eq "raw"
$_->[1] =~ /$args->[0]/
Truth table60%3/5
A or B && C
A= $_->[0] eq "text"B= $_->[0] eq "raw"C= $_->[1] =~ /$args->[0]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | if $class eq 'text'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # ":any-link", ":link" and ":visited" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 836 | ▶ | if ($class eq 'any-link' || $class eq 'link' || $class eq 'visited') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$class eq "any-link" or $class eq "link" or $class eq "visited"
$class eq "any-link" or $class eq "link"
MC/DC100%3/3
$class eq "any-link" or $class eq "link" or $class eq "visited"
$class eq "any-link"
$class eq "link"
$class eq "visited"
Truth table100%4/4
A or B or C
A= $class eq "any-link"B= $class eq "link"C= $class eq "visited"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 39 | ▶ | return undef unless $current->[0] eq 'tag' && exists $current->[2]{href}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$current->[0] eq "tag" and exists $current->[2]{"href"}
MC/DC50%1/2
$current->[0] eq "tag" and exists $current->[2]{"href"}
$current->[0] eq "tag"
exists $current->[2]{"href"}
Truth table66%2/3
A and B
A= $current->[0] eq "tag"B= exists $current->[2]{"href"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 21 | return !!grep { $current->[1] eq $_ } qw(a area link); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # ":only-child" or ":only-of-type" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 797 | ▶ | if ($class eq 'only-child' || $class eq 'only-of-type') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$class eq "only-child" or $class eq "only-of-type"
MC/DC100%2/2
$class eq "only-child" or $class eq "only-of-type"
$class eq "only-child"
$class eq "only-of-type"
Truth table100%3/3
A or B
A= $class eq "only-child"B= $class eq "only-of-type"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 26 | ▶ | my $type = $class eq 'only-of-type' ? $current->[1] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 26 | ▶ | $_ ne $current and return undef for @{_siblings($current, $type)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # ":nth-child", ":nth-last-child", ":nth-of-type" or ":nth-last-of-type" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 771 | ▶ | if (ref $args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 763 | ▶ | my $type = $class eq 'nth-of-type' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$class eq "nth-of-type" or $class eq "nth-last-of-type"
MC/DC100%2/2
$class eq "nth-of-type" or $class eq "nth-last-of-type"
$class eq "nth-of-type"
$class eq "nth-last-of-type"
Truth table100%3/3
A or B
A= $class eq "nth-of-type"B= $class eq "nth-last-of-type"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | || $class eq 'nth-last-of-type' ? $current->[1] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 763 | my @siblings = @{_siblings($current, $type)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 763 | my $index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 763 | for my $i (0 .. $#siblings) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 3204 | ▶ | $index = $i, last if $siblings[$i] eq $current; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 763 | ▶ | $index = $#siblings - $index if $class eq 'nth-last-child' || $class eq 'nth-last-of-type'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$class eq "nth-last-child" or $class eq "nth-last-of-type"
MC/DC100%2/2
$class eq "nth-last-child" or $class eq "nth-last-of-type"
$class eq "nth-last-child"
$class eq "nth-last-of-type"
Truth table100%3/3
A or B
A= $class eq "nth-last-child"B= $class eq "nth-last-of-type"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 763 | $index++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 763 | my $delta = $index - $args->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 763 | ▶ | return 1 if $delta == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 646 | ▶ | return $args->[0] != 0 && ($delta < 0) == ($args->[0] < 0) && $delta % $args->[0] == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$args->[0] != 0 && $delta < 0 == $args->[0] < 0 && $delta % $args->[0] == 0
$args->[0] != 0 and $delta < 0 == $args->[0] < 0
MC/DC100%3/3
$args->[0] != 0 && $delta < 0 == $args->[0] < 0 && $delta % $args->[0] == 0
$args->[0] != 0
$delta < 0 == $args->[0] < 0
$delta % $args->[0] == 0
Truth table100%4/4
A and B && C
A= $args->[0] != 0B= $delta < 0 == $args->[0] < 0C= $delta % $args->[0] == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # Everything else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 8 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 94 | ▶ | sub _root { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_root: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 94 | my $tree = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 94 | ▶ | $tree = $tree->[3] while $tree->[0] ne 'root'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 94 | return $tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 1174 | ▶ | sub _select { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_select: called CC=13 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 1174 | my ($one, $scope, $group) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # Scoped selectors require the whole tree to be searched | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1174 | my $tree = $scope; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 1174 | ▶ | ($group, $tree) = (_absolutize($group), _root($scope)) if grep { _is_scoped($_) } @$group; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # Without combinators the first match in document order can be returned right away | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1174 | ▶ | if ($one && !grep { @$_ != 1 || !ref $_->[0] } @$group) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$one and not grep({@$_ != 1 or not ref $_->[0];} @$group)
@$_ != 1 || !ref($_->[0])
MC/DC100%2/2
$one and not grep({@$_ != 1 or not ref $_->[0];} @$group)
$one
not grep({@$_ != 1 or not ref $_->[0];} @$group)
MC/DC100%2/2
@$_ != 1 || !ref($_->[0])
@$_ != 1
!ref($_->[0])
Truth table100%3/3
A and not(B)
A= $oneB= not grep({@$_ != 1 or not ref $_->[0];} @$group)
Truth table100%3/3
A || not(B)
A= @$_ != 1B= !ref($_->[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 497 | ▶ | my @queue = @$tree[($tree->[0] eq 'root' ? 1 : 4) .. $#$tree]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 497 | ▶ | while (my $current = shift @queue) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 2822 | ▶ | next unless $current->[0] eq 'tag'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1330 | ▶ | return $current if grep { _selector($_->[0], $current, $tree, $scope) } @$group; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 882 | unshift @queue, @$current[4 .. $#$current]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 49 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # Pool includes $tree so ":scope" can match it, but results exclude it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 677 | my $tags = _all_tags($tree); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 677 | my %match = map { $_ => 1 } @{_evaluate($group, $tree, $scope, [$tree, @$tags])}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 677 | my @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 677 | for my $node (@$tags) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 5696 | ▶ | next unless $match{$node}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1245 | ▶ | return $node if $one; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 1038 | push @results, $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 470 | ▶ | return $one ? undef : \@results; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 11820 | ▶ | sub _selector { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_selector: called CC=13 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 11820 | my ($selector, $current, $tree, $scope) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # The root might be the scope | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 11820 | my $is_tag = $current->[0] eq 'tag'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 11820 | for my $s (@$selector) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 12877 | my $type = $s->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # Tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 12877 | ▶ | if ($is_tag && $type eq 'tag') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$is_tag and $type eq "tag"
MC/DC100%2/2
$is_tag and $type eq "tag"
$is_tag
$type eq "tag"
Truth table100%3/3
A and B
A= $is_tagB= $type eq "tag"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 8785 | ▶ | return undef if defined $s->[1] && $current->[1] !~ $s->[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $s->[1] and not $current->[1] =~ /$s->[1]/
MC/DC100%2/2
defined $s->[1] and not $current->[1] =~ /$s->[1]/
defined $s->[1]
not $current->[1] =~ /$s->[1]/
Truth table100%3/3
A and not(B)
A= defined $s->[1]B= not $current->[1] =~ /$s->[1]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 3684 | ▶ | return undef if defined $s->[2] && !_namespace($s->[2], $current); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $s->[2] and not _namespace($s->[2], $current)
MC/DC100%2/2
defined $s->[2] and not _namespace($s->[2], $current)
defined $s->[2]
not _namespace($s->[2], $current)
Truth table100%3/3
A and not(B)
A= defined $s->[2]B= not _namespace($s->[2], $current)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # Attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1645 | ▶ | elsif ($is_tag && $type eq 'attr') { return undef unless _attr(@$s[1, 2], $current) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$is_tag and $type eq "attr"
MC/DC100%2/2
$is_tag and $type eq "attr"
$is_tag
$type eq "attr"
Truth table100%3/3
A and B
A= $is_tagB= $type eq "attr"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # Pseudo-class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1836 | ▶ | elsif ($type eq 'pc') { return undef unless _pc(@$s[1, 2], $current, $tree, $scope) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # No match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 611 | else { return undef } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 3559 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 892 | ▶ | sub _siblings { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_siblings: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 892 | my ($current, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 892 | my $parent = $current->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 892 | ▶ | my @siblings = grep { $_->[0] eq 'tag' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | @$parent[($parent->[0] eq 'root' ? 1 : 4) .. $#$parent]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 892 | ▶ | @siblings = grep { $type eq $_->[1] } @siblings if defined $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 892 | return \@siblings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 6 | ▶ | sub _step_back { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_step_back: called CC=13 SCAR=28.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 6 | my ($combinator, $node, $scope) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # " " (ancestors) and ">" (parent only) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 6 | ▶ | if ($combinator eq ' ' || $combinator eq '>') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$combinator eq " " or $combinator eq ">"
MC/DC50%1/2
$combinator eq " " or $combinator eq ">"
$combinator eq " "
$combinator eq ">"
Truth table66%2/3
A or B
A= $combinator eq " "B= $combinator eq ">"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 2 | my @ancestors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2 | ▶ | while ($node ne $scope && $node->[0] ne 'root' && ($node = $node->[3])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$node ne $scope and $node->[0] ne "root" and $node = $node->[3]
$node ne $scope and $node->[0] ne "root"
MC/DC0%0/3
$node ne $scope and $node->[0] ne "root" and $node = $node->[3]
$node ne $scope
$node->[0] ne "root"
$node = $node->[3]
Truth table25%1/4
A and B and C
A= $node ne $scopeB= $node->[0] ne "root"C= $node = $node->[3]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 2 | push @ancestors, $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 2 | ▶ | last if $combinator eq '>' || $node eq $scope; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$combinator eq ">" or $node eq $scope
MC/DC0%0/2
$combinator eq ">" or $node eq $scope
$combinator eq ">"
$node eq $scope
Truth table33%1/3
A or B
A= $combinator eq ">"B= $node eq $scope
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 2 | return @ancestors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # "~" (preceding siblings) and "+" (immediately preceding) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 4 | ▶ | return () if $node->[0] eq 'root'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 4 | my @prev; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 4 | for my $sib (@{_siblings($node)}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 14 | ▶ | last if $sib eq $node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 10 | push @prev, $sib; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 4 | ▶ | return $combinator eq '+' ? ($prev[-1] || ()) : @prev; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$prev[-1] or ()
MC/DC0%0/2
$prev[-1] or ()
$prev[-1]
()
Truth table33%1/3
A or B
A= $prev[-1]B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 1729 | ▶ | sub _step_forward { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_step_forward: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 1729 | my ($combinator, $node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # " " (descendants) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 1729 | ▶ | return @{_all_tags($node)} if $combinator eq ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | # ">" (children only) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 645 | ▶ | return grep { $_->[0] eq 'tag' } @$node[($node->[0] eq 'root' ? 1 : 4) .. $#$node] if $combinator eq '>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # "~" (following siblings) and "+" (immediately following) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 99 | ▶ | return () if $node->[0] eq 'root'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 99 | my (@next, $found); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 99 | for my $sib (@{_siblings($node)}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 405 | ▶ | push @next, $sib if $found; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 405 | ▶ | $found = 1 if $sib eq $node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 99 | ▶ | return $combinator eq '+' ? ($next[0] || ()) : @next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$next[0] or ()
MC/DC50%1/2
$next[0] or ()
$next[0]
()
Truth table66%2/3
A or B
A= $next[0]B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 3885 | ▶ | sub _unescape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unescape: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 3885 | ▶ | return undef unless defined(my $value = shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # Remove escaped newlines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 2296 | $value =~ s/\\\n//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # Unescape Unicode characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 2296 | $value =~ s/\\([0-9a-fA-F]{1,6})\s?/pack 'U', hex $1/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # Remove backslash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 2296 | $value =~ s/\\//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 2296 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 410 | ▶ | sub _value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 410 | my ($op, $value, $insensitive) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 410 | ▶ | return undef unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 366 | ▶ | $value = ($insensitive ? '(?i)' : '') . quotemeta _unescape($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | # "~=" (word) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 366 | ▶ | return qr/(?:^|\s+)$value(?:\s+|$)/ if $op eq '~'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | # "|=" (hyphen-separated) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 294 | ▶ | return qr/^$value(?:-|$)/ if $op eq '|'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | # "*=" (contains) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 284 | ▶ | return qr/$value/ if $op eq '*'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | # "^=" (begins with) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 272 | ▶ | return qr/^$value/ if $op eq '^'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # "$=" (ends with) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 240 | ▶ | return qr/$value$/ if $op eq '$'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # Everything else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 209 | return qr/^$value$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | =for Pod::Coverage *EVERYTHING* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||