TPath/Context.pm

filter: Statementstmt 33.3% 14 / 42 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 28.5% 4 / 14 Podpod 70.0% 7 / 10 totaltotal 33.7% 25 / 74 CC 5 SCAR 12.7
CC
5
Cov
28%
previous
6.0
first
6.0
expression
6.0
CRAP 3.6
« TPath/Function.pm ↑ Summary TPath/StderrLog.pm »
1 package TPath::Context;
2 1 $TPath::Context::VERSION = '1.007';
3 # ABSTRACT: the context in which a node is evaluated during a search
4  
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use overload '""' => \&to_string;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # To be regarded as private. Let TPath code create contexts.
14 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
15 0 my $class = shift;
16 0 my %params = @_;
17 0 my $self = [ $params{n}, $params{i}, [], undef ];
18 0 bless $self, $class;
19 }
20  
21 # A constructor that constructs a new context by augmenting an existing context.
22 # Expects a new node and the collection from which it was chosen. To be regarded
23 # as private.
24 0 ▶sub bud {
Subroutine bud: not called CC=1 SCAR=6.9
Pod undocumented
25  
26 # my ( $self, $n ) = @_;
27 0 return bless [ $_[1], $_[0][1], [ $_[0][0], @{ $_[0][2] } ], undef ];
28 }
29  
30 #Makes a context that doesn't preserve the path.
31 0 ▶sub wrap {
Subroutine wrap: not called CC=1 SCAR=6.9
Pod undocumented
32  
33 # my ( $self, $n ) = @_;
34 0 return bless [ $_[1], $_[0][1], [], undef ];
35 }
36  
37  
38 0 ▶sub previous {
Subroutine previous: not called CC=2 SCAR=17.9
Pod documented
39 0 my $self = shift;
40 0 my @previous = @{ $self->[2] };
41 0 my $n = shift @previous;
42 0 ▶ return () unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 0 0
43 0 return bless [ $n, $self->[1], \@previous, undef ];
44 }
45  
46  
47 0 ▶sub first {
Subroutine first: not called CC=2 SCAR=17.9
Pod documented
48 0 my $self = shift;
49 0 ▶ return $self unless @{ $self->[2] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->[2];} 0 0 0
50 0 $self->wrap( $self->[2][-1] );
51 }
52  
53  
54 0 ▶sub n { $_[0][0] }
Subroutine n: not called CC=1 SCAR=6.9
Pod documented
55  
56  
57 0 ▶sub i { $_[0][1] }
Subroutine i: not called CC=1 SCAR=6.9
Pod documented
58  
59  
60 0 ▶sub path { $_[0][2] }
Subroutine path: not called CC=1 SCAR=6.9
Pod documented
61  
62  
63 0 ▶sub expression {
Subroutine expression: not called CC=2 SCAR=17.9
Pod documented
64 0 ▶ return $_[0][3] if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 0 0 0
65 0 return $_[0][3] = $_[1];
66 }
67  
68  
69 0 ▶sub to_string {
Subroutine to_string: not called CC=2 SCAR=17.9
Pod documented
70 0 my $s;
71 0 eval { $s = "$_[0][0]" };
72 0 ▶ if ($@) { # workaround for odd overload bug
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
73 0 $s = 'memaddr' . refaddr $_[0][0];
74 }
75 0 return $s;
76 }
77  
78 1 1;
79  
80 __END__
« TPath/Function.pm ↑ Summary TPath/StderrLog.pm »