| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 73 | 0 | $s = 'memaddr' . refaddr $_[0][0]; | |||||||||
| 74 | } | ||||||||||
| 75 | 0 | return $s; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 1 | 1; | |||||||||
| 79 | |||||||||||
| 80 | __END__ | ||||||||||