| 1 | package YAX::Query; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use YAX::Constants qw/:all/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | our $rx_iden = "[a-zA-Z0-9-\\:_]+|\\*"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | our $rx_item = "\\[(?:(?:-?\\d+)|(?:\\d+\\s*\\.\\.\\s*-?\\d+))\\]"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | our $rx_func = "\\b(?:parent|document|id)\\b\\(\\)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | our $rx_type = "#(?:text|processing-instruction|comment|cdata|node)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | our $rx_filt = "\\(.+?\\)(?:$rx_item)?(?=(?:\\.|\$))"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | our $rx_attr = "@(?:$rx_iden)(?:$rx_item)?"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | our $rx_elmt = "(?:$rx_iden)(?:$rx_item)?"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | our $rx_term = "(?:$rx_type)(?:$rx_item)?|(?:$rx_func)(?:$rx_item)?"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | our $rx_frag = "(?:$rx_attr)|(?:$rx_term)|(?:$rx_elmt)|(?:$rx_filt)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | our $rx_chld = "\\.(?:$rx_frag)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | our $rx_desc = "\\.\\.(?:$rx_frag)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | our $rx_expr = "$rx_desc|$rx_chld"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | our $RX_TEST = "^(?:$rx_expr)+\$"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | our $RX_EXEC = $rx_expr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | our $RX_ITEM = '\[(-?\d+)\]$'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | our $RX_SLCE = '\[(-?\d+)\s*\.\.\s*(-?\d+)\]$'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | our %CACHE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 14 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 14 | my ( $class, $node ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 14 | my $self = bless [ $node ], $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 14 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 14 | ▶ | sub tokenize { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tokenize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 14 | my ( $self, $expr ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 14 | $expr =~ /$RX_EXEC/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 14 | ▶ | sub compile { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile: called CC=31 SCAR=41.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 14 | my ( $self, $expr ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 14 | ▶ | $expr = ".$expr" unless substr( $expr, 0, 1 ) eq '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 14 | ▶ | die "failed to parse `$expr'" unless $expr =~ /$RX_TEST/g; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return @{ $CACHE{ $expr } } if exists $CACHE{ $expr }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 14 | my @exec; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 14 | my @tokens = $self->tokenize( $expr ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 14 | my ( $index, $start, $end, $seen_flat ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 14 | foreach my $token ( @tokens ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 28 | $token = substr( $token, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 28 | undef( $index ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 28 | undef( $start ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 28 | undef( $end ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 28 | ▶ | if ( $token =~ /$RX_ITEM/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | $token =~ s/$RX_ITEM//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | $index = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } elsif ( $token =~ /$RX_SLCE/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | $token =~ s/$RX_SLCE//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | $start = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | $end = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 28 | ▶ | if ( substr( $token, 0, 1 ) eq '.' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 14 | ▶ | $seen_flat && die "cannot select `$token' following `$seen_flat'"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 14 | push @exec, [ 'descendants', substr( $token, 1 ) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | elsif ( $token eq '#node' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | $seen_flat && die "cannot select `$token' following `$seen_flat'"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | push @exec, [ 'children' ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | elsif ( $token eq '*' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $seen_flat && die "cannot select `$token' following `$seen_flat'"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | push @exec, [ 'children', ELEMENT_NODE ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | elsif ( $token eq '#text' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | $seen_flat && die "cannot select `$token' following `$seen_flat'"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | push @exec, [ 'children', TEXT_NODE ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | $seen_flat = $token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | elsif ( $token eq '#cdata' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $seen_flat = $token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | push @exec, [ 'children', CDATA_SECTION_NODE ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | elsif ( $token eq '#processing-instruction' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $seen_flat && die "cannot select `$token' following `$seen_flat'"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | push @exec, [ 'children', PROCESSING_INSTRUCTION_NODE ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | elsif ( $token eq '#comment' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | $seen_flat && die "cannot select `$token' following `$seen_flat'"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | push @exec, [ 'children', COMMENT_NODE ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | elsif ( $token eq '@*' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | $seen_flat && die "cannot select `$token' following `$seen_flat'"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | push @exec, [ 'attributes' ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $seen_flat = $token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | elsif ( substr( $token, 0, 1 ) eq '@' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $seen_flat && die "cannot select `$token' following `$seen_flat'"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | push @exec, [ 'attribute', substr( $token, 1 ) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $seen_flat = $token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | elsif ( substr( $token, 0, 1 ) eq '(' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | push @exec, [ 'filter', substr( $token, 1, -1 ) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | elsif ( $token eq 'parent()' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | $seen_flat && die "cannot select `$token' following `$seen_flat'"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | push @exec, [ 'parent' ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 7 | ▶ | $seen_flat && die "cannot select `$token' following `$seen_flat'"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 7 | push @exec, [ 'child', $token ] | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 28 | ▶ | if ( defined $index ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 6 | push @exec, [ 'item', 0+$index ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ▶ | elsif ( defined $start and defined $end ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $start and defined $end
MC/DC50%1/2
defined $start and defined $end
defined $start
defined $end
Truth table66%2/3
A and B
A= defined $startB= defined $end
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | push @exec, [ 'slice', 0+$start, 0+$end ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 14 | $CACHE{ $expr } = [ @exec ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 14 | return @exec; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 14 | ▶ | sub select { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 14 | my ( $self, $expr ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 14 | my @exec = $self->compile( $expr ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 14 | my ( $meth, @list ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 14 | foreach my $exec ( @exec ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 35 | $meth = shift @$exec; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 35 | ▶ | if ( $meth eq 'item' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | @$self = ( $self->[ $exec->[0] ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | elsif ( $meth eq 'slice' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | @$self = @$self[ $exec->[0] .. $exec->[1] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | elsif ( $meth eq 'filter' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 3 | $self->filter( $exec->[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 25 | @list = @$self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 25 | @$self = ( ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 25 | foreach my $node ( @list ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 37 | $self->$meth( $node, @$exec ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 14 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | ▶ | sub parent { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | my ( $self, $node ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 3 | push @$self, $node->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 3 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 4 | ▶ | sub children { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
children: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | my ( $self, $node, $type ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | ▶ | if ( UNIVERSAL::can( $node, 'children' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 4 | foreach my $child ( @{ $node->children } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 14 | ▶ | next if defined $type and ( $child->type != $type ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $type and $child->type != $type
MC/DC100%2/2
defined $type and $child->type != $type
defined $type
$child->type != $type
Truth table100%3/3
A and B
A= defined $typeB= $child->type != $type
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 13 | push @$self, $child; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 15 | ▶ | sub child { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
child: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 15 | my ( $self, $node, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 15 | ▶ | if ( UNIVERSAL::can( $node, 'children' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 15 | foreach my $child ( @{ $node->children } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 48 | ▶ | next unless $child->name eq $name; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 16 | push @$self, $child; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 15 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | ▶ | sub attributes { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | my ( $self, $node ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | push @$self, $node->attributes; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | sub attribute { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attribute: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my ( $self, $node, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | push @$self, $node->attributes->{ $name }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 14 | ▶ | sub descendants { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
descendants: called CC=12 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 14 | my ( $self, $node, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 14 | ▶ | $name = '*' unless $name; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 14 | ▶ | if ( UNIVERSAL::can( $node, 'children' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 14 | my @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 14 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 14 | foreach my $child ( reverse @{ $node->children } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 30 | $stack[ $count++ ] = $child; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 14 | ▶ | while ( --$count >= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 624 | my $n = $stack[ $count ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 624 | ▶ | if ( $name eq '*' and $n->type == ELEMENT_NODE ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$name eq "*" and $n->type == 1
MC/DC0%0/2
$name eq "*" and $n->type == 1
$name eq "*"
$n->type == 1
Truth table33%1/3
A and B
A= $name eq "*"B= $n->type == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | push @$self, $n; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | ▶ | elsif ( $name eq '#processing-instruction' and | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$name eq "#processing-instruction" and $n->type == 7
MC/DC0%0/2
$name eq "#processing-instruction" and $n->type == 7
$name eq "#processing-instruction"
$n->type == 7
Truth table33%1/3
A and B
A= $name eq "#processing-instruction"B= $n->type == 7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | ( $n->type == PROCESSING_INSTRUCTION_NODE ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | push @$self, $n; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | elsif ( $n->name eq $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 53 | push @$self, $n; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 624 | ▶ | if ( UNIVERSAL::can( $n, 'children' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 214 | foreach my $child ( reverse @{ $n->children } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 594 | $stack[ $count++ ] = $child; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 14 | undef( @stack ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 14 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | ▶ | sub filter { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filter: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 3 | my ( $self, $test ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 3 | ▶ | unless ( ref $test eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 3 | my $orig = $test; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | $test =~ s/@([a-zA-Z\-:._]+)\b/\$_->{$1}/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 3 | $orig = $test; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 3 | $test = mk_code( $test ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | ▶ | die "$@ while compiling filter: `$orig'" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 3 | @$self = grep { &$test } @$self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 3 | ▶ | sub mk_code { eval 'sub { '.$_[-1].' }' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mk_code: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||