| 1 | package HTML::Selector::XPath; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use 5.008_001; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | our $VERSION = '0.28'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | our @EXPORT_OK = qw(selector_to_xpath); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | *import = \&Exporter::import; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 23 | ▶ | sub selector_to_xpath { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selector_to_xpath: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 23 | __PACKAGE__->new(shift)->to_xpath(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # XXX: Identifiers should also allow any characters U+00A0 and higher, and any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # escaped characters. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 8 | my $ident = qr/(?![0-9]|-[-0-9])[-_a-zA-Z0-9]+/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 8 | my $reg = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # tag name/id/class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | element => qr/^([#.]?)([^\s'"#.\/:@,=~>()\[\]|]*)((\|)([a-z0-9\\*_-]*))?/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # attribute presence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | attr1 => qr/^\[ \s* ($ident) \s* \]/x, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # attribute value match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | attr2 => qr/^\[ \s* ($ident) \s* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ( [~|*^\$!]? = ) \s* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | (?: ($ident) | "([^"]*)" | '([^']*)') \s* \] /x, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | badattr => qr/^\[/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | attrN => qr/^:not\(/i, # we chop off the closing parenthesis below in the code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | pseudo => qr/^:([-\w]+\(?)/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # adjacency/direct descendance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | combinator => qr/^(\s*[>+~\s](?!,))/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # rule separator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | comma => qr/^\s*,\s*/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 184 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 184 | my($class, $exp) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 184 | bless { expression => $exp }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub selector { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selector: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $self->{expression} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $self->{expression}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 30 | ▶ | sub convert_attribute_match { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert_attribute_match: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 30 | my ($left,$op,$right) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # negation (e.g. [input!="text"]) isn't implemented in CSS, but include it anyway: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 30 | ▶ | if ($op eq '!=') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | "\@$left!='$right'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } elsif ($op eq '~=') { # substring attribute match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | "contains(concat(' ', \@$left, ' '), ' $right ')"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } elsif ($op eq '*=') { # real substring attribute match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | "contains(\@$left, '$right')"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } elsif ($op eq '|=') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | "\@$left='$right' or starts-with(\@$left, '$right-')"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } elsif ($op eq '^=') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | "starts-with(\@$left,'$^N')"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } elsif ($op eq '$=') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | my $n = length($^N) - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | "substring(\@$left,string-length(\@$left)-$n)='$^N'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } else { # exact match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 10 | "\@$left='$^N'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 48 | ▶ | sub _generate_child { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_child: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 48 | my ($direction,$name,$a,$b) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 48 | ▶ | if ($a == 0) { # 0n+b | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 32 | $b--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 32 | "[count($direction-sibling::$name) = $b and parent::*]" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } elsif ($a > 0) { # an + b | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 11 | return "[not((count($direction-sibling::$name)+1)<$b) and ((count($direction-sibling::$name) + 1) - $b) mod $a = 0 and parent::*]" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } else { # -an + $b | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 5 | $a = -$a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | return "[not((count($direction-sibling::$name)+1)>$b) and (($b - (count($direction-sibling::$name) + 1)) mod $a) = 0 and parent::*]" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 32 | ▶ | sub nth_child { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nth_child: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 32 | my ($a,$b) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 32 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 15 | ($a,$b) = (0,$a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 32 | _generate_child('preceding', '*', $a, $b); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 11 | ▶ | sub nth_last_child { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nth_last_child: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 11 | my ($a,$b) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 11 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 7 | ($a,$b) = (0,$a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 11 | _generate_child('following', '*', $a, $b); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # A hacky recursive descent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # Only descends for :not(...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 25 | ▶ | sub consume_An_plus_B { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
consume_An_plus_B: called CC=9 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 25 | my( $rrule ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 25 | my( $A, $B ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 25 | ▶ | if( $$rrule =~ s/^odd\s*\)// ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ($A,$B) = (2, 1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } elsif( $$rrule =~ s/^even\s*\)// ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | ($A,$B) = (2, 0) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } elsif( $$rrule =~ s/^\s*(-?\d+)\s*\)// ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 9 | ($A,$B) = (0, $1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } elsif( $$rrule =~ s/^\s*(-?\d*)\s*n\s*(?:\+\s*(\d+))?\s*\)// ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 14 | ▶ | ($A,$B) = ($1, $2 || 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$2 || 0
MC/DC100%1/1
$2 || 0
$2
Truth table100%2/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 14 | ▶ | if( ! defined $A ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $A = '0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } elsif( $A eq '-') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | $A = '-1'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } elsif( $A eq '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | $A = '1'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | croak "Can't parse formula from '$$rrule'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 25 | return ($A, $B); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 190 | ▶ | sub consume { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
consume: called CC=52 SCAR=40.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 190 | my ($self, $rule, %parms) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 190 | ▶ | my $root = $parms{root} || '/'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$parms{'root'} || '/'
MC/DC100%1/1
$parms{'root'} || '/'
$parms{'root'}
Truth table100%2/2
A
A= $parms{'root'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 190 | ▶ | return [$rule,''] if $rule =~ m!^/!; # If we start with a slash, we're already an XPath?! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 189 | my @parts = ("$root/"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 189 | my $last_rule = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 189 | my @next_parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | my $wrote_tag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 189 | my $root_index = 0; # points to the current root | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Loop through each "unit" of the rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 189 | ▶ | while (length $rule && $rule ne $last_rule) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $rule and $rule ne $last_rule
MC/DC100%2/2
length $rule and $rule ne $last_rule
length $rule
$rule ne $last_rule
Truth table100%3/3
A and B
A= length $ruleB= $rule ne $last_rule
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 291 | $last_rule = $rule; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 291 | $rule =~ s/^\s*|\s*$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 291 | ▶ | last unless length $rule; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # Prepend explicit first selector if we have an implicit selector | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # (that is, if we start with a combinator) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 291 | ▶ | if ($rule =~ /$reg->{combinator}/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | $rule = "* $rule"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # Match elements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 291 | ▶ | if ($rule =~ s/$reg->{element}//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 291 | my ($id_class,$name,$lang) = ($1,$2,$3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # to add *[1]/self:: for follow-sibling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 291 | ▶ | if (@next_parts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | push @parts, @next_parts; #, (pop @parts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | @next_parts = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 291 | ▶ | my $tag = $id_class eq '' ? $name || '*' : '*'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$name or "*"
MC/DC100%1/1
$name or "*"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 291 | ▶ | if (defined $parms{prefix} and not $tag =~ /[*:|]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $parms{"prefix"} and not $tag =~ /[*:|]/
MC/DC100%2/2
defined $parms{"prefix"} and not $tag =~ /[*:|]/
defined $parms{"prefix"}
not $tag =~ /[*:|]/
Truth table100%3/3
A and not(B)
A= defined $parms{"prefix"}B= not $tag =~ /[*:|]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 12 | $tag = join ':', $parms{prefix}, $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 291 | ▶ | if (! $wrote_tag++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 250 | push @parts, $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # XXX Shouldn't the RE allow both, ID and class? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 291 | ▶ | if ($id_class eq '#') { # ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 21 | push @parts, "[\@id='$name']"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } elsif ($id_class eq '.') { # class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 27 | push @parts, "[contains(concat(' ', normalize-space(\@class), ' '), ' $name ')]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # Match attribute selectors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 291 | ▶ | if ($rule =~ s/$reg->{attr2}//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 23 | push @parts, "[", convert_attribute_match( $1, $2, $^N ), "]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } elsif ($rule =~ s/$reg->{attr1}//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # If we have no tag output yet, write the tag: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 6 | ▶ | if (! $wrote_tag++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | push @parts, '*'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 6 | push @parts, "[\@$1]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } elsif ($rule =~ $reg->{badattr}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 14 | Carp::croak "Invalid attribute-value selector '$rule'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # Match negation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 277 | ▶ | if ($rule =~ s/$reg->{attrN}//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # Now we parse the rest, and after parsing the subexpression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # has stopped, we must find a matching closing parenthesis: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 14 | ▶ | if ($rule =~ s/$reg->{attr2}//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 7 | push @parts, "[not(", convert_attribute_match( $1, $2, $^N ), ")]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } elsif ($rule =~ s/$reg->{attr1}//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | push @parts, "[not(\@$1)]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } elsif ($rule =~ /$reg->{badattr}/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | Carp::croak "Invalid negated attribute-value selector ':not($rule)'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 6 | my( $new_parts, $leftover ) = $self->consume( $rule, %parms ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 6 | shift @$new_parts; # remove '//' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 6 | my $xpath = join '', @$new_parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 6 | push @parts, "[not(self::$xpath)]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 6 | $rule = $leftover; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 14 | ▶ | $rule =~ s!^\s*\)!! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | or die "Unbalanced parentheses at '$rule'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # Ignore pseudoclasses/pseudoelements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 277 | ▶ | while ($rule =~ s/$reg->{pseudo}//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 84 | ▶ | if ( my @expr = $self->parse_pseudo($1, \$rule) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 17 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | push @parts, @expr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } elsif ( $1 eq 'disabled') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | push @parts, '[@disabled]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } elsif ( $1 eq 'checked') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | push @parts, '[@checked]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } elsif ( $1 eq 'selected') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | push @parts, '[@selected]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } elsif ( $1 eq 'text') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | push @parts, '*[@type="text"]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } elsif ( $1 eq 'first-child') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # Translates to :nth-child(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 13 | push @parts, nth_child(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } elsif ( $1 eq 'last-child') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | push @parts, nth_last_child(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } elsif ( $1 eq 'only-child') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | push @parts, nth_child(1), nth_last_child(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } elsif ($1 =~ /^lang\($/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 11 | ▶ | $rule =~ s/\s*([\w\-]+)\s*\)// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | or Carp::croak "Can't parse language part from $rule"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 11 | push @parts, "[\@xml:lang='$1' or starts-with(\@xml:lang, '$1-')]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } elsif ($1 =~ /^nth-child\(\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 17 | my( $A, $B ) = consume_An_plus_B(\$rule); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 17 | push @parts, nth_child($A, $B); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } elsif ($1 =~ /^nth-last-child\(\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | my( $A, $B ) = consume_An_plus_B(\$rule); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | push @parts, nth_last_child($A, $B); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } elsif ($1 =~ /^first-of-type\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | my $type = $parts[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | push @parts, _generate_child('preceding', $type, 0, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } elsif ($1 =~ /^nth-of-type\(\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 4 | my( $A, $B ) = consume_An_plus_B(\$rule); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | my $type = $parts[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | push @parts, _generate_child('preceding', $type, $A, $B); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } elsif ($1 =~ /^last-of-type$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | push @parts, "[last()]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # Err?! This one does not really exist in the CSS spec... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # Why did I add this? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } elsif ($1 =~ /^contains\($/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 13 | ▶ | if( $rule =~ s/^\s*"([^"]*)"\s*\)// ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 11 | push @parts, qq{[text()[contains(string(.),"$1")]]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } elsif( $rule =~ s/^\s*'([^']*)'\s*\)// ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | push @parts, qq{[text()[contains(string(.),"$1")]]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | return( \@parts, $rule ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | #die "Malformed string in :contains(): '$rule'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } elsif ( $1 eq 'root') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # This will give surprising results if you do E > F:root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | $parts[$root_index] = $root; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } elsif ( $1 eq 'empty') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 3 | push @parts, "[not(* or text())]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | Carp::croak "Can't translate '$1' pseudo-class"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # Match combinators (whitespace, >, + and ~) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 277 | ▶ | if ($rule =~ s/$reg->{combinator}//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 53 | my $match = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 53 | ▶ | if ($match =~ />/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 13 | push @parts, "/"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } elsif ($match =~ /\+/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 5 | push @parts, "/following-sibling::*[1]/self::"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } elsif ($match =~ /\~/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 11 | push @parts, "/following-sibling::"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } elsif ($match =~ /^\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 24 | push @parts, "//" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | die "Weird combinator '$match'" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # new context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 53 | undef $wrote_tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # Match commas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 277 | ▶ | if ($rule =~ s/$reg->{comma}//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 8 | push @parts, " | ", "$root/"; # ending one rule and beginning another | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 8 | $root_index = $#parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 8 | undef $wrote_tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 175 | return \@parts, $rule | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 184 | ▶ | sub to_xpath { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_xpath: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 184 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 184 | ▶ | my $rule = $self->{expression} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 184 | my %parms = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 184 | my($result,$leftover) = $self->consume( $rule, %parms ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 170 | ▶ | $leftover | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | and die "Invalid rule, couldn't parse '$leftover'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 170 | return join '', @$result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 81 | ▶ | sub parse_pseudo { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_pseudo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # nop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||