TPath/Predicate/Index.pm

filter: Statementstmt 22.5% 14 / 62 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 22.2% 2 / 9 Podpod 0.0% 0 / 2 totaltotal 12.6% 16 / 127 CC 24 SCAR 37.7
CC
24
Cov
13%
__ANON__
72.0
__ANON__
56.0
__ANON__
42.0
CRAP 43.4
« TPath/Grammar.pm ↑ Summary TPath/Stringifiable.pm »
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
BranchTrueFalseTotal
if ($self->f->one_based) 0 0 0
28 0 ▶ die '[0] predicate used in path expecting 1-based indices'
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 0 0 0
29 if $i == 0;
30 0 ▶ $i-- if $i > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i > 0 0 0 0
31 }
32 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
33 0 ▶ return shift->[$i] // ();
Condition0%0/3
+(shift())->[$i] // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
+(shift())->[$i] // ()
+(shift())->[$i] ()
Truth table0%0/3
A // B
A= +(shift())->[$i]B= ()
ABresult
1X1
011
000
34 }
35 0 ▶ if $self->outer or !$self->_anywhere;
Branch: 1 branch
BranchTrueFalseTotal
if $self->outer or not $self->_anywhere 0 0 0
Condition0%0/3
$self->outer or not $self->_anywhere
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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
l!l&&r!l&&!r
000
MC/DC0%0/2
$index //= $ctx->i
$index $ctx->i
Truth table0%0/3
A //= B
A= $indexB= $ctx->i
ABresult
1X1
011
000
41 0 my $p = $index->parent( $ctx->n );
42 0 ▶ $p = defined $p ? refaddr $p : -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $p ? : 0 0 0
43 0 ▶ next if $tally{$p};
Branch: 1 branch
BranchTrueFalseTotal
if $tally{$p} 0 0 0
44 0 $tally{$p} = 1;
45 0 push @ret, $ctx;
46 }
47 0 return @ret;
48 }
49 0 ▶ if $i == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 0 0 0
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
l!l&&r!l&&!r
000
MC/DC0%0/2
$index //= $ctx->i
$index $ctx->i
Truth table0%0/3
A //= B
A= $indexB= $ctx->i
ABresult
1X1
011
000
55 0 my $p = $index->parent( $ctx->n );
56 0 ▶ $p = defined $p ? refaddr $p : -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $p ? : 0 0 0
57 0 my $ar;
58 0 ▶ unless ( $ar = $tally{$p} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ar = $tally{$p}) 0 0 0
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
BranchTrueFalseTotal
if $ctx 0 0 0
68 }
69 0 return @ret;
70 }
71 0 ▶ if $i < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 0 0 0
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
l!l&&r!l&&!r
000
MC/DC0%0/2
$index //= $ctx->i
$index $ctx->i
Truth table0%0/3
A //= B
A= $indexB= $ctx->i
ABresult
1X1
011
000
77 0 my $p = $index->parent( $ctx->n );
78 0 ▶ $p = defined $p ? refaddr $p : -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $p ? : 0 0 0
79 0 ▶ $tally{$p} //= 0;
Condition0%0/2
$tally{$p} //= 0
l!l
00
MC/DC0%0/1
$tally{$p} //= 0
$tally{$p}
Truth table0%0/2
A
A= $tally{$p}
Aresult
11
00
80 0 ▶ push @ret, $ctx if $tally{$p}++ == $i;
Branch: 1 branch
BranchTrueFalseTotal
if $tally{$p}++ == $i 0 0 0
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__
« TPath/Grammar.pm ↑ Summary TPath/Stringifiable.pm »