| 1 | package JIP::DataPath; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '0.044'; | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 1 | our @EXPORT_OK = qw(path); | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | sub path { | ||||||||||||||||||||||||||||||||
|
Subroutine
path: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 15 | 4 | my ($document) = @ARG; | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 4 | return __PACKAGE__->new( document => $document ); | |||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | 13 | ▶ | sub default_value { | ||||||||||||||||||||||||||||||||
|
Subroutine
default_value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 21 | 13 | return __PACKAGE__ . '::default_value'; | |||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 9 | ▶ | sub is_default_value { | ||||||||||||||||||||||||||||||||
|
Subroutine
is_default_value: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 25 | 9 | my ( $self, $value ) = @ARG; | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 9 | ▶ | return 0 if !defined $value; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 28 | 8 | ▶ | return 0 if ref $value; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | return 0 if $value ne $self->default_value(); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 1 | return 1; | |||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 67 | ▶ | sub document { | ||||||||||||||||||||||||||||||||
|
Subroutine
document: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 35 | 67 | my ($self) = @ARG; | |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 67 | return $self->{document}; | |||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | 21 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 41 | 21 | my ( $class, %param ) = @ARG; | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | # Mandatory params | ||||||||||||||||||||||||||||||||||
| 44 | 21 | ▶ | if ( !exists $param{document} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | 1 | croak 'Mandatory argument "document" is missing'; | |||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | return bless( | ||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||
| 50 | document => $param{document}, | ||||||||||||||||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||||||||||||||||
| 52 | 20 | $class, | |||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | 27 | ▶ | sub get { | ||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=9 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 57 | 27 | my ( $self, $path_parts, $default_value ) = @ARG; | |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 27 | ▶ | if ( @{$path_parts} == 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 60 | 7 | return $self->document(); | |||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 20 | my ( $contains, $context ) = $self->_accessor($path_parts); | |||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | 20 | ▶ | return $default_value if !$contains; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 10 | ▶ | my $last_part = $path_parts->[-1] // q{}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$path_parts->[-1] // ""
MC/DC0%0/1
$path_parts->[-1] // ""
$path_parts->[-1]
Truth table50%1/2
A
A= $path_parts->[-1]
| |||||||||||||||||||||||||||||||||||
| 68 | 10 | ▶ | my $type = ref $context // q{}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
ref $context // ""
MC/DC0%0/1
ref $context // ""
ref $context
Truth table50%1/2
A
A= ref $context
| |||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 10 | ▶ | if ( $type eq 'HASH' && length $last_part ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$type eq "HASH" and length $last_part
MC/DC50%1/2
$type eq "HASH" and length $last_part
$type eq "HASH"
length $last_part
Truth table66%2/3
A and B
A= $type eq "HASH"B= length $last_part
| |||||||||||||||||||||||||||||||||||
| 71 | 8 | return $context->{$last_part}; | |||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||
| 73 | ▶ | elsif ( $type eq 'ARRAY' && $last_part =~ m{^\d+$}x ) { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "ARRAY" and $last_part =~ /^\d+$/x
MC/DC0%0/2
$type eq "ARRAY" and $last_part =~ /^\d+$/x
$type eq "ARRAY"
$last_part =~ /^\d+$/x
Truth table33%1/3
A and B
A= $type eq "ARRAY"B= $last_part =~ /^\d+$/x
| |||||||||||||||||||||||||||||||||||
| 74 | 2 | return $context->[$last_part]; | |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 0 | return $default_value; | |||||||||||||||||||||||||||||||||
| 78 | } ## end sub get | ||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | sub get_new { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_new: called CC=9 SCAR=26.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 81 | 5 | my ( $self, $path_parts, $default_value ) = @ARG; | |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 5 | ▶ | if ( @{$path_parts} == 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 84 | 2 | return path( $self->document() ); | |||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | 3 | my ( $contains, $context ) = $self->_accessor($path_parts); | |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 3 | ▶ | return $default_value if !$contains; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | 1 | ▶ | my $last_part = $path_parts->[-1] // q{}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$path_parts->[-1] // ""
MC/DC0%0/1
$path_parts->[-1] // ""
$path_parts->[-1]
Truth table50%1/2
A
A= $path_parts->[-1]
| |||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | my $type = ref $context // q{}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
ref $context // ""
MC/DC0%0/1
ref $context // ""
ref $context
Truth table50%1/2
A
A= ref $context
| |||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | if ( $type eq 'HASH' && length $last_part ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$type eq "HASH" and length $last_part
MC/DC0%0/2
$type eq "HASH" and length $last_part
$type eq "HASH"
length $last_part
Truth table33%1/3
A and B
A= $type eq "HASH"B= length $last_part
| |||||||||||||||||||||||||||||||||||
| 95 | 1 | return path( $context->{$last_part} ); | |||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||
| 97 | ▶ | elsif ( $type eq 'ARRAY' && $last_part =~ m{^\d+$}x ) { | |||||||||||||||||||||||||||||||||
|
Condition0%0/3
$type eq "ARRAY" and $last_part =~ /^\d+$/x
MC/DC0%0/2
$type eq "ARRAY" and $last_part =~ /^\d+$/x
$type eq "ARRAY"
$last_part =~ /^\d+$/x
Truth table0%0/3
A and B
A= $type eq "ARRAY"B= $last_part =~ /^\d+$/x
| |||||||||||||||||||||||||||||||||||
| 98 | 0 | return path( $context->[$last_part] ); | |||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 0 | return $default_value; | |||||||||||||||||||||||||||||||||
| 102 | } ## end sub get_new | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 9 | ▶ | sub contains { | ||||||||||||||||||||||||||||||||
|
Subroutine
contains: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 105 | 9 | my ( $self, @xargs ) = @ARG; | |||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | 9 | my ($contains) = $self->_accessor(@xargs); | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 9 | return $contains; | |||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | 9 | ▶ | sub set { | ||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=9 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 113 | 9 | my ( $self, $path_parts, $value ) = @ARG; | |||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | 9 | ▶ | if ( @{$path_parts} == 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 116 | 4 | $self->_set_document($value); | |||||||||||||||||||||||||||||||||
| 117 | 4 | return 1; | |||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | 5 | my ( $contains, $context ) = $self->_accessor($path_parts); | |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | 5 | ▶ | return 0 if !$contains; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | 5 | ▶ | my $last_part = $path_parts->[-1] // q{}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$path_parts->[-1] // ""
MC/DC0%0/1
$path_parts->[-1] // ""
$path_parts->[-1]
Truth table50%1/2
A
A= $path_parts->[-1]
| |||||||||||||||||||||||||||||||||||
| 125 | 5 | ▶ | my $type = ref $context // q{}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
ref $context // ""
MC/DC0%0/1
ref $context // ""
ref $context
Truth table50%1/2
A
A= ref $context
| |||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||
| 127 | 5 | ▶ | if ( $type eq 'HASH' && length $last_part ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$type eq "HASH" and length $last_part
MC/DC50%1/2
$type eq "HASH" and length $last_part
$type eq "HASH"
length $last_part
Truth table66%2/3
A and B
A= $type eq "HASH"B= length $last_part
| |||||||||||||||||||||||||||||||||||
| 128 | 4 | $context->{$last_part} = $value; | |||||||||||||||||||||||||||||||||
| 129 | 4 | return 1; | |||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||
| 131 | ▶ | elsif ( $type eq 'ARRAY' && $last_part =~ m{^\d+$}x ) { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "ARRAY" and $last_part =~ /^\d+$/x
MC/DC0%0/2
$type eq "ARRAY" and $last_part =~ /^\d+$/x
$type eq "ARRAY"
$last_part =~ /^\d+$/x
Truth table33%1/3
A and B
A= $type eq "ARRAY"B= $last_part =~ /^\d+$/x
| |||||||||||||||||||||||||||||||||||
| 132 | 1 | $context->[$last_part] = $value; | |||||||||||||||||||||||||||||||||
| 133 | 1 | return 1; | |||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 137 | } ## end sub set | ||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | 5 | ▶ | sub perform { | ||||||||||||||||||||||||||||||||
|
Subroutine
perform: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 140 | 5 | my ( $self, $method, $path_parts, @xargs ) = @ARG; | |||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | 5 | return $self->$method( $path_parts, @xargs ); | |||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | 4 | ▶ | sub _set_document { | ||||||||||||||||||||||||||||||||
|
Subroutine
_set_document: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 146 | 4 | my ( $self, $document ) = @ARG; | |||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | 4 | $self->{document} = $document; | |||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||
| 150 | 4 | return; | |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 46 | ▶ | sub _accessor { | ||||||||||||||||||||||||||||||||
|
Subroutine
_accessor: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||
| 154 | 46 | my ( $self, $path_parts ) = @ARG; | |||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | 46 | my $context = $self->document(); | |||||||||||||||||||||||||||||||||
| 157 | 46 | my $last_index = $#{$path_parts}; | |||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | 46 | foreach my $part_index ( 0 .. $last_index ) { | |||||||||||||||||||||||||||||||||
| 160 | 80 | my $part = $path_parts->[$part_index]; | |||||||||||||||||||||||||||||||||
| 161 | 80 | ▶ | my $type = ref $context // q{}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
ref $context // ""
MC/DC0%0/1
ref $context // ""
ref $context
Truth table50%1/2
A
A= ref $context
| |||||||||||||||||||||||||||||||||||
| 162 | 80 | my $last = $part_index == $last_index; | |||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||
| 164 | 80 | ▶ | if ( $type eq 'HASH' && exists $context->{$part} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$type eq "HASH" and exists $context->{$part}
MC/DC100%2/2
$type eq "HASH" and exists $context->{$part}
$type eq "HASH"
exists $context->{$part}
Truth table100%3/3
A and B
A= $type eq "HASH"B= exists $context->{$part}
| |||||||||||||||||||||||||||||||||||
| 165 | 49 | ▶ | return ( 1, $context ) if $last; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | 29 | $context = $context->{$part}; | |||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||
| 169 | 15 | ▶ | elsif ( $type eq 'ARRAY' && $part =~ m{^\d+$}x && @{$context} > $part ) { | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
$type eq "ARRAY" and $part =~ /^\d+$/x and @{$context;} > $part
$type eq "ARRAY" and $part =~ /^\d+$/x
MC/DC33%1/3
$type eq "ARRAY" and $part =~ /^\d+$/x and @{$context;} > $part
$type eq "ARRAY"
$part =~ /^\d+$/x
@{$context;} > $part
Truth table50%2/4
A and B and C
A= $type eq "ARRAY"B= $part =~ /^\d+$/xC= @{$context;} > $part
| |||||||||||||||||||||||||||||||||||
| 170 | 15 | ▶ | return ( 1, $context ) if $last; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | 8 | $context = $context->[$part]; | |||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||
| 174 | else { | ||||||||||||||||||||||||||||||||||
| 175 | 16 | return ( 0, undef ); | |||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | 3 | return ( 1, $context ); | |||||||||||||||||||||||||||||||||
| 180 | } ## end sub _accessor | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||
| 184 | __END__ | ||||||||||||||||||||||||||||||||||