| 1 | package DOM::Tiny::_CSS; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 1 | my $ESCAPE_RE = qr/\\[^0-9a-fA-F]|\\[0-9a-fA-F]{1,6}/; | |||||||||||||||||||||||||||||||
| 9 | 1 | my $ATTR_RE = qr/ | |||||||||||||||||||||||||||||||
| 10 | \[ | ||||||||||||||||||||||||||||||||
| 11 | ((?:$ESCAPE_RE|[\w\-])+) # Key | ||||||||||||||||||||||||||||||||
| 12 | (?: | ||||||||||||||||||||||||||||||||
| 13 | (\W)?= # Operator | ||||||||||||||||||||||||||||||||
| 14 | (?:"((?:\\"|[^"])*)"|'((?:\\'|[^'])*)'|([^\]]+?)) # Value | ||||||||||||||||||||||||||||||||
| 15 | (?:\s+(i))? # Case-sensitivity | ||||||||||||||||||||||||||||||||
| 16 | )? | ||||||||||||||||||||||||||||||||
| 17 | \] | ||||||||||||||||||||||||||||||||
| 18 | /x; | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | sub new { | ||||||||||||||||||||||||||||||||
| 21 | 871 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 22 | 871 | ▶ | 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
| |||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | sub tree { | ||||||||||||||||||||||||||||||||
| 26 | 871 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
tree: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 27 | 871 | ▶ | return $self->{tree} unless @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | 0 | $self->{tree} = shift; | |||||||||||||||||||||||||||||||
| 29 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | sub matches { | ||||||||||||||||||||||||||||||||
| 33 | 29 | ▶ | my $tree = shift->tree; | ||||||||||||||||||||||||||||||
|
Subroutine
matches: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 34 | 29 | ▶ | return $tree->[0] ne 'tag' ? undef : _match(_compile(shift), $tree, $tree); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 389 | ▶ | sub select { _select(0, shift->tree, _compile(@_)) } | ||||||||||||||||||||||||||||||
|
Subroutine
select: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 38 | 453 | ▶ | sub select_one { _select(1, shift->tree, _compile(@_)) } | ||||||||||||||||||||||||||||||
|
Subroutine
select_one: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | sub _ancestor { | ||||||||||||||||||||||||||||||||
| 41 | 1295 | ▶ | my ($selectors, $current, $tree, $one, $pos) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_ancestor: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 1295 | ▶ | while ($current = $current->[3]) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | 1363 | ▶ | return undef if $current->[0] eq 'root' || $current eq $tree; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$current->[0] eq "root" or $current eq $tree
MC/DC100%2/2
$current->[0] eq "root" or $current eq $tree
$current->[0] eq "root"
$current eq $tree
Truth table100%3/3
A or B
A= $current->[0] eq "root"B= $current eq $tree
| |||||||||||||||||||||||||||||||||
| 45 | 1281 | ▶ | return 1 if _combinator($selectors, $current, $tree, $pos); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | 205 | ▶ | last if $one; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 137 | return undef; | |||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | sub _attr { | ||||||||||||||||||||||||||||||||
| 53 | 981 | ▶ | my ($name_re, $value_re, $current) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_attr: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 981 | my $attrs = $current->[2]; | |||||||||||||||||||||||||||||||
| 56 | 981 | for my $name (keys %$attrs) { | |||||||||||||||||||||||||||||||
| 57 | 837 | ▶ | next unless $name =~ $name_re; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | 531 | ▶ | return 1 unless defined $attrs->{$name} && defined $value_re; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $attrs->{$name} and defined $value_re
MC/DC100%2/2
defined $attrs->{$name} and defined $value_re
defined $attrs->{$name}
defined $value_re
Truth table100%3/3
A and B
A= defined $attrs->{$name}B= defined $value_re
| |||||||||||||||||||||||||||||||||
| 59 | 497 | ▶ | return 1 if $attrs->{$name} =~ $value_re; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 638 | return undef; | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | sub _combinator { | ||||||||||||||||||||||||||||||||
| 66 | 6877 | ▶ | my ($selectors, $current, $tree, $pos) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_combinator: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | # Selector | ||||||||||||||||||||||||||||||||
| 69 | 6877 | ▶ | return undef unless my $c = $selectors->[$pos]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | 6877 | ▶ | if (ref $c) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | 6877 | ▶ | return undef unless _selector($c, $current); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 72 | 2794 | ▶ | return 1 unless $c = $selectors->[++$pos]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | # ">" (parent only) | ||||||||||||||||||||||||||||||||
| 76 | 1392 | ▶ | return _ancestor($selectors, $current, $tree, 1, ++$pos) if $c eq '>'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | # "~" (preceding siblings) | ||||||||||||||||||||||||||||||||
| 79 | 518 | ▶ | return _sibling($selectors, $current, $tree, 0, ++$pos) if $c eq '~'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | # "+" (immediately preceding siblings) | ||||||||||||||||||||||||||||||||
| 82 | 473 | ▶ | return _sibling($selectors, $current, $tree, 1, ++$pos) if $c eq '+'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | # " " (ancestor) | ||||||||||||||||||||||||||||||||
| 85 | 421 | return _ancestor($selectors, $current, $tree, 0, ++$pos); | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | sub _compile { | ||||||||||||||||||||||||||||||||
| 89 | 898 | ▶ | my $css = "$_[0]"; | ||||||||||||||||||||||||||||||
|
Subroutine
_compile: called CC=19 SCAR=29.4
| |||||||||||||||||||||||||||||||||
| 90 | 898 | $css =~ s/^\s+//; | |||||||||||||||||||||||||||||||
| 91 | 898 | $css =~ s/\s+$//; | |||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 898 | my $group = [[]]; | |||||||||||||||||||||||||||||||
| 94 | 898 | ▶ | while (my $selectors = $group->[-1]) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 95 | 3244 | ▶ | 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]
| |||||||||||||||||||||||||||||||||
| 96 | 3244 | my $last = $selectors->[-1]; | |||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | # Separator | ||||||||||||||||||||||||||||||||
| 99 | 3244 | ▶ | if ($css =~ /\G\s*,\s*/gc) { push @$group, [] } | ||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | # Combinator | ||||||||||||||||||||||||||||||||
| 102 | 592 | elsif ($css =~ /\G\s*([ >+~])\s*/gc) { push @$selectors, $1 } | |||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | # Class or ID | ||||||||||||||||||||||||||||||||
| 105 | elsif ($css =~ /\G([.#])((?:$ESCAPE_RE\s|\\.|[^,.#:[ >~+])+)/gco) { | ||||||||||||||||||||||||||||||||
| 106 | 131 | ▶ | my ($name, $op) = $1 eq '.' ? ('class', '~') : ('id', ''); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | 131 | push @$last, ['attr', _name($name), _value($op, $2)]; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | # Attributes | ||||||||||||||||||||||||||||||||
| 111 | elsif ($css =~ /\G$ATTR_RE/gco) { | ||||||||||||||||||||||||||||||||
| 112 | 197 | ▶ | push @$last, [ | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 113 | 'attr', _name($1), | ||||||||||||||||||||||||||||||||
| 114 | _value( | ||||||||||||||||||||||||||||||||
| 115 | defined($2) ? $2 : '', | ||||||||||||||||||||||||||||||||
| 116 | defined($3) ? $3 : defined($4) ? $4 : $5, | ||||||||||||||||||||||||||||||||
| 117 | $6 | ||||||||||||||||||||||||||||||||
| 118 | ), | ||||||||||||||||||||||||||||||||
| 119 | ]; | ||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | # Pseudo-class | ||||||||||||||||||||||||||||||||
| 123 | elsif ($css =~ /\G:([\w\-]+)(?:\(((?:\([^)]+\)|[^)])+)\))?/gcs) { | ||||||||||||||||||||||||||||||||
| 124 | 179 | my ($name, $args) = (lc $1, $2); | |||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | # ":not" (contains more selectors) | ||||||||||||||||||||||||||||||||
| 127 | 179 | ▶ | $args = _compile($args) if $name eq 'not'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | # ":nth-*" (with An+B notation) | ||||||||||||||||||||||||||||||||
| 130 | 179 | ▶ | $args = _equation($args) if $name =~ /^nth-/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | # ":first-*" (rewrite to ":nth-*") | ||||||||||||||||||||||||||||||||
| 133 | 179 | ▶ | ($name, $args) = ("nth-$1", [0, 1]) if $name =~ /^first-(.+)$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | # ":last-*" (rewrite to ":nth-*") | ||||||||||||||||||||||||||||||||
| 136 | 179 | ▶ | ($name, $args) = ("nth-$name", [-1, 1]) if $name =~ /^last-/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | 179 | push @$last, ['pc', $name, $args]; | |||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | # Tag | ||||||||||||||||||||||||||||||||
| 142 | elsif ($css =~ /\G((?:$ESCAPE_RE\s|\\.|[^,.#:[ >~+])+)/gco) { | ||||||||||||||||||||||||||||||||
| 143 | 1240 | ▶ | push @$last, ['tag', _name($1)] unless $1 eq '*'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 898 | else {last} | |||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 898 | return $group; | |||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 58 | ▶ | sub _empty { $_[0][0] eq 'comment' || $_[0][0] eq 'pi' } | ||||||||||||||||||||||||||||||
|
Subroutine
_empty: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | sub _equation { | ||||||||||||||||||||||||||||||||
| 155 | 98 | ▶ | return [0, 0] unless my $equation = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_equation: called CC=9 SCAR=22.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | # "even" | ||||||||||||||||||||||||||||||||
| 158 | 96 | ▶ | return [2, 2] if $equation =~ /^\s*even\s*$/i; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | # "odd" | ||||||||||||||||||||||||||||||||
| 161 | 87 | ▶ | return [2, 1] if $equation =~ /^\s*odd\s*$/i; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | # "4", "+4" or "-4" | ||||||||||||||||||||||||||||||||
| 164 | 75 | ▶ | return [0, $1] if $equation =~ /^\s*((?:\+|-)?\d+)\s*$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | # "n", "4n", "+4n", "-4n", "n+1", "4n-1", "+4n-1" (and other variations) | ||||||||||||||||||||||||||||||||
| 167 | 51 | ▶ | return [0, 0] | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 168 | unless $equation =~ /^\s*((?:\+|-)?(?:\d+)?)?n\s*((?:\+|-)\s*\d+)?\s*$/i; | ||||||||||||||||||||||||||||||||
| 169 | 50 | ▶ | 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
| |||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | sub _match { | ||||||||||||||||||||||||||||||||
| 173 | 5391 | ▶ | my ($group, $current, $tree) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_match: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 174 | 5391 | ▶ | _combinator([reverse @$_], $current, $tree, 0) and return 1 for @$group; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 175 | 3993 | return undef; | |||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | 1554 | ▶ | sub _name {qr/(?:^|:)\Q@{[_unescape(shift)]}\E$/} | ||||||||||||||||||||||||||||||
|
Subroutine
_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | sub _pc { | ||||||||||||||||||||||||||||||||
| 181 | 1354 | ▶ | my ($class, $args, $current) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_pc: called CC=19 SCAR=29.4
| |||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | # ":checked" | ||||||||||||||||||||||||||||||||
| 184 | return exists $current->[2]{checked} || exists $current->[2]{selected} | ||||||||||||||||||||||||||||||||
| 185 | 1354 | ▶ | 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'}
| |||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | # ":not" | ||||||||||||||||||||||||||||||||
| 188 | 1153 | ▶ | return !_match($args, $current, $current) if $class eq 'not'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | # ":empty" | ||||||||||||||||||||||||||||||||
| 191 | 1027 | ▶ | return !grep { !_empty($_) } @$current[4 .. $#$current] if $class eq 'empty'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | # ":root" | ||||||||||||||||||||||||||||||||
| 194 | 1003 | ▶ | 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'
| |||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | # ":nth-child", ":nth-last-child", ":nth-of-type" or ":nth-last-of-type" | ||||||||||||||||||||||||||||||||
| 197 | 956 | ▶ | if (ref $args) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 198 | 908 | ▶ | my $type = $class =~ /of-type$/ ? $current->[1] : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 199 | 908 | my @siblings = @{_siblings($current, $type)}; | |||||||||||||||||||||||||||||||
| 200 | 908 | ▶ | @siblings = reverse @siblings if $class =~ /^nth-last/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | 908 | for my $i (0 .. $#siblings) { | |||||||||||||||||||||||||||||||
| 203 | 3951 | ▶ | next if (my $result = $args->[0] * $i + $args->[1]) < 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 204 | 2848 | ▶ | last unless my $sibling = $siblings[$result - 1]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 205 | 2670 | ▶ | return 1 if $sibling eq $current; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | # ":only-child" or ":only-of-type" | ||||||||||||||||||||||||||||||||
| 210 | ▶ | elsif ($class eq 'only-child' || $class eq 'only-of-type') { | |||||||||||||||||||||||||||||||
|
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"
| |||||||||||||||||||||||||||||||||
| 211 | 40 | ▶ | my $type = $class eq 'only-of-type' ? $current->[1] : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 212 | 40 | ▶ | $_ ne $current and return undef for @{_siblings($current, $type)}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 213 | 7 | return 1; | |||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||
| 216 | 535 | return undef; | |||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | sub _select { | ||||||||||||||||||||||||||||||||
| 220 | 842 | ▶ | my ($one, $tree, $group) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_select: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||
| 222 | 842 | my @results; | |||||||||||||||||||||||||||||||
| 223 | 842 | ▶ | my @queue = @$tree[($tree->[0] eq 'root' ? 1 : 4) .. $#$tree]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 224 | 842 | ▶ | while (my $current = shift @queue) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 225 | 13226 | ▶ | next unless $current->[0] eq 'tag'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||
| 227 | 5237 | unshift @queue, @$current[4 .. $#$current]; | |||||||||||||||||||||||||||||||
| 228 | 5237 | ▶ | next unless _match($group, $current, $tree); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 229 | 1349 | ▶ | $one ? return $current : push @results, $current; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | 424 | ▶ | return $one ? undef : \@results; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | sub _selector { | ||||||||||||||||||||||||||||||||
| 236 | 6877 | ▶ | my ($selector, $current) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_selector: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | 6877 | for my $s (@$selector) { | |||||||||||||||||||||||||||||||
| 239 | 7763 | my $type = $s->[0]; | |||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | # Tag | ||||||||||||||||||||||||||||||||
| 242 | 7763 | ▶ | if ($type eq 'tag') { return undef unless $current->[1] =~ $s->[1] } | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | # Attribute | ||||||||||||||||||||||||||||||||
| 245 | 981 | ▶ | elsif ($type eq 'attr') { return undef unless _attr(@$s[1, 2], $current) } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | # Pseudo-class | ||||||||||||||||||||||||||||||||
| 248 | 1354 | ▶ | elsif ($type eq 'pc') { return undef unless _pc(@$s[1, 2], $current) } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | 2794 | return 1; | |||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | sub _sibling { | ||||||||||||||||||||||||||||||||
| 255 | 97 | ▶ | my ($selectors, $current, $tree, $immediate, $pos) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_sibling: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||
| 257 | 97 | my $found; | |||||||||||||||||||||||||||||||
| 258 | 97 | for my $sibling (@{_siblings($current)}) { | |||||||||||||||||||||||||||||||
| 259 | 261 | ▶ | return $found if $sibling eq $current; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||
| 261 | # "+" (immediately preceding sibling) | ||||||||||||||||||||||||||||||||
| 262 | 187 | ▶ | if ($immediate) { $found = _combinator($selectors, $sibling, $tree, $pos) } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | # "~" (preceding sibling) | ||||||||||||||||||||||||||||||||
| 265 | 79 | ▶ | else { return 1 if _combinator($selectors, $sibling, $tree, $pos) } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | sub _siblings { | ||||||||||||||||||||||||||||||||
| 272 | 1045 | ▶ | my ($current, $type) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_siblings: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | 1045 | my $parent = $current->[3]; | |||||||||||||||||||||||||||||||
| 275 | 1045 | ▶ | my @siblings = grep { $_->[0] eq 'tag' } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 276 | @$parent[($parent->[0] eq 'root' ? 1 : 4) .. $#$parent]; | ||||||||||||||||||||||||||||||||
| 277 | 1045 | ▶ | @siblings = grep { $type eq $_->[1] } @siblings if defined $type; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | 1045 | return \@siblings; | |||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | sub _unescape { | ||||||||||||||||||||||||||||||||
| 283 | 1855 | ▶ | my $value = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_unescape: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||
| 285 | # Remove escaped newlines | ||||||||||||||||||||||||||||||||
| 286 | 1855 | $value =~ s/\\\n//g; | |||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||
| 288 | # Unescape Unicode characters | ||||||||||||||||||||||||||||||||
| 289 | 1855 | $value =~ s/\\([0-9a-fA-F]{1,6})\s?/pack 'U', hex $1/ge; | |||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | # Remove backslash | ||||||||||||||||||||||||||||||||
| 292 | 1855 | $value =~ s/\\//g; | |||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||
| 294 | 1855 | return $value; | |||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | sub _value { | ||||||||||||||||||||||||||||||||
| 298 | 328 | ▶ | my ($op, $value, $insensitive) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_value: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||
| 299 | 328 | ▶ | return undef unless defined $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 300 | 301 | ▶ | $value = ($insensitive ? '(?i)' : '') . quotemeta _unescape($value); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||
| 302 | # "~=" (word) | ||||||||||||||||||||||||||||||||
| 303 | 301 | ▶ | return qr/(?:^|\s+)$value(?:\s+|$)/ if $op eq '~'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||
| 305 | # "*=" (contains) | ||||||||||||||||||||||||||||||||
| 306 | 238 | ▶ | return qr/$value/ if $op eq '*'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | # "^=" (begins with) | ||||||||||||||||||||||||||||||||
| 309 | 227 | ▶ | return qr/^$value/ if $op eq '^'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | # "$=" (ends with) | ||||||||||||||||||||||||||||||||
| 312 | 197 | ▶ | return qr/$value$/ if $op eq '$'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||
| 314 | # Everything else | ||||||||||||||||||||||||||||||||
| 315 | 166 | return qr/^$value$/; | |||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||
| 318 | 1 | 1; | |||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||
| 320 | =for Pod::Coverage *EVERYTHING* | ||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | =cut | ||||||||||||||||||||||||||||||||