| 1 | package TPath::Predicate::Index; | ||||||||||||||||||||||||||||
| 2 | 1 | $TPath::Predicate::Index::VERSION = '1.007'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: implements the C<[0]> in C<//a/b[0]> | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Scalar::Util qw(refaddr); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | with 'TPath::Predicate'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | has idx => ( is => 'ro', isa => 'Int', required => 1 ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | has f => (is => 'ro', does => 'TPath::Forester', required => 1); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # needed for lazy specification of algorithm | ||||||||||||||||||||||||||||
| 18 | 1 | has _anywhere => (is=>'rw', isa => 'Bool', default => 0); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | has algorithm => ( | ||||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||
| 22 | isa => 'CodeRef', | ||||||||||||||||||||||||||||
| 23 | lazy => 1, | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 25 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 26 | 0 | my $i = $self->idx; | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ( $self->f->one_based ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | die '[0] predicate used in path expecting 1-based indices' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | if $i == 0; | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $i-- if $i > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | return shift->[$i] // (); | ||||||||||||||||||||||||||
|
Condition0%0/3
+(shift())->[$i] // ()
MC/DC0%0/2
+(shift())->[$i] // ()
+(shift())->[$i]
()
Truth table0%0/3
A // B
A= +(shift())->[$i]B= ()
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if $self->outer or !$self->_anywhere; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->outer or not $self->_anywhere
MC/DC0%0/2
$self->outer or not $self->_anywhere
$self->outer
not $self->_anywhere
Truth table0%0/3
A or not(B)
A= $self->outerB= not $self->_anywhere
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 37 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 38 | 0 | my ( $index, %tally, @ret ); | |||||||||||||||||||||||||||
| 39 | 0 | for my $ctx (@$c) { | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | $index //= $ctx->i; | ||||||||||||||||||||||||||
|
Condition0%0/3
$index //= $ctx->i
MC/DC0%0/2
$index //= $ctx->i
$index
$ctx->i
Truth table0%0/3
A //= B
A= $indexB= $ctx->i
| |||||||||||||||||||||||||||||
| 41 | 0 | my $p = $index->parent( $ctx->n ); | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | $p = defined $p ? refaddr $p : -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | next if $tally{$p}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | $tally{$p} = 1; | |||||||||||||||||||||||||||
| 45 | 0 | push @ret, $ctx; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 0 | return @ret; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if $i == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 51 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 52 | 0 | my ( $index, %tally, @parents ); | |||||||||||||||||||||||||||
| 53 | 0 | for my $ctx (@$c) { | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | $index //= $ctx->i; | ||||||||||||||||||||||||||
|
Condition0%0/3
$index //= $ctx->i
MC/DC0%0/2
$index //= $ctx->i
$index
$ctx->i
Truth table0%0/3
A //= B
A= $indexB= $ctx->i
| |||||||||||||||||||||||||||||
| 55 | 0 | my $p = $index->parent( $ctx->n ); | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | $p = defined $p ? refaddr $p : -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | my $ar; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | unless ( $ar = $tally{$p} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | push @parents, $p; | |||||||||||||||||||||||||||
| 60 | 0 | $ar = $tally{$p} = []; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 0 | push @$ar, $ctx; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 0 | my @ret; | |||||||||||||||||||||||||||
| 65 | 0 | for my $p (@parents) { | |||||||||||||||||||||||||||
| 66 | 0 | my $ctx = $tally{$p}[$i]; | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | push @ret, $ctx if $ctx; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 0 | return @ret; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if $i < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 73 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 74 | 0 | my ( $index, %tally, @ret ); | |||||||||||||||||||||||||||
| 75 | 0 | for my $ctx (@$c) { | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | $index //= $ctx->i; | ||||||||||||||||||||||||||
|
Condition0%0/3
$index //= $ctx->i
MC/DC0%0/2
$index //= $ctx->i
$index
$ctx->i
Truth table0%0/3
A //= B
A= $indexB= $ctx->i
| |||||||||||||||||||||||||||||
| 77 | 0 | my $p = $index->parent( $ctx->n ); | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | $p = defined $p ? refaddr $p : -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $tally{$p} //= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tally{$p} //= 0
MC/DC0%0/1
$tally{$p} //= 0
$tally{$p}
Truth table0%0/2
A
A= $tally{$p}
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | push @ret, $ctx if $tally{$p}++ == $i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 0 | return @ret; | |||||||||||||||||||||||||||
| 83 | 0 | }; | |||||||||||||||||||||||||||
| 84 | }, | ||||||||||||||||||||||||||||
| 85 | 1 | ); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub filter { | ||||||||||||||||||||||||||
|
Subroutine
filter: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 88 | 0 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||
| 89 | 0 | return $self->algorithm->($c); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub to_string { | ||||||||||||||||||||||||||
|
Subroutine
to_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 93 | 0 | $_[0]->idx; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | 1; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||