Path.pm

filter: Statementstmt 93.4% 86 / 92 Branchbran 64.2% 9 / 14 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 24 / 24 Podpod 100% 11 / 11 totaltotal 90.3% 141 / 156 CC 13 SCAR 9.3
CC
13
Cov
89%
set
6.7
new
3.5
values
3.0
CRAP 2.5
« Path/Tokenizer.pm ↑ Summary Path/Constants.pm »
1 13 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package JSON::Path;
6 13 $JSON::Path::VERSION = '0.51';
7 # VERSION
8  
9 13 ▶use Exporter::Shiny qw/ jpath jpath1 jpath_map /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 our $AUTHORITY = 'cpan:POPEFELIX';
11 13 our $Safe = 1;
12  
13 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 13 ▶use JSON::MaybeXS qw/decode_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 13 ▶use JSON::Path::Evaluator;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 13 ▶use Scalar::Util qw[blessed];
Subroutine BEGIN: called CC=1 SCAR=0.0
17 13 ▶use LV ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 13 ▶use overload '""' => \&to_string;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 sub jpath {
22 3 ▶ my ( $object, $expression ) = @_;
Subroutine jpath: called CC=1 SCAR=0.0
Pod documented
23 3 my @return = __PACKAGE__->new($expression)->values($object);
24 }
25  
26 sub jpath1 : lvalue {
27 4 ▶ my ( $object, $expression ) = @_;
Subroutine jpath1: called CC=1 SCAR=0.0
Pod documented
28 4 __PACKAGE__->new($expression)->value($object);
29 }
30  
31 sub jpath_map (&$$) {
32 1 ▶ my ( $coderef, $object, $expression ) = @_;
Subroutine jpath_map: called CC=1 SCAR=0.0
Pod documented
33 1 return __PACKAGE__->new($expression)->map( $object, $coderef );
34 }
35  
36 sub new {
37 32 ▶ my ( $class, $expression ) = @_;
Subroutine new: called CC=3 SCAR=12.5
Pod documented
38 32 ▶ return $expression
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($expression) and $expression->isa(__PACKAGE__) 0 32 32
Condition33%1/3
builtin::blessed($expression) and $expression->isa(__PACKAGE__)
!ll&&!rl&&r
3200
MC/DC0%0/2
builtin::blessed($expression) and $expression->isa(__PACKAGE__)
builtin::blessed($expression) $expression->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($expression)B= $expression->isa(__PACKAGE__)
ABresult
0X0
100
111
39 if blessed($expression) && $expression->isa(__PACKAGE__);
40 32 return bless \$expression, $class;
41 }
42  
43 sub to_string {
44 71 ▶ my ($self) = @_;
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
45 71 return $$self;
46 }
47  
48 sub paths {
49 6 ▶ my ( $self, $object ) = @_;
Subroutine paths: called CC=1 SCAR=0.0
Pod documented
50 6 my @paths = JSON::Path::Evaluator::evaluate_jsonpath( $object, "$self", want_path => 1);
51 6 return @paths;
52 }
53  
54 sub get {
55 9 ▶ my ( $self, $object ) = @_;
Subroutine get: called CC=2 SCAR=6.9
Pod documented
56 9 my @values = $self->values($object);
57 9 ▶ return wantarray ? @values : $values[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 1 9
58 }
59  
60 sub set {
61 10 ▶ my ( $self, $object, $value, $limit ) = @_;
Subroutine set: called CC=6 SCAR=19.1
Pod documented
62  
63 10 ▶ if ( !ref $object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $object) 0 10 10
64 # warn if not called internally. If called internally (i.e. from value()) we will already have warned.
65 0 my @c = caller(0);
66 0 ▶ if ( $c[1] !~ /JSON\/Path\.pm$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c[1] =~ m[JSON/Path\.pm$]) 0 0 0
67 0 carp qq{Useless attempt to set a value on a non-reference};
68 }
69 }
70 10 my $count = 0;
71 10 my @refs = JSON::Path::Evaluator::evaluate_jsonpath( $object, "$self", want_ref => 1 );
72 10 for my $ref (@refs) {
73 12 ${$ref} = $value;
74 12 ++$count;
75 12 ▶ last if $limit && ( $count >= $limit );
Branch: 1 branch
BranchTrueFalseTotal
if $limit and $count >= $limit 8 4 12
Condition100%3/3
$limit and $count >= $limit
!ll&&!rl&&r
228
MC/DC100%2/2
$limit and $count >= $limit
$limit $count >= $limit
Truth table100%3/3
A and B
A= $limitB= $count >= $limit
ABresult
0X0
100
111
76 }
77 10 return $count;
78 }
79  
80 sub value : lvalue {
81 13 ▶ my ( $self, $object ) = @_;
Subroutine value: called CC=1 SCAR=0.4
Pod documented
82 LV::lvalue(
83 get => sub {
84 8 ▶ my ($value) = $self->get($object);
Subroutine __ANON__: called CC=1 SCAR=0.0
85 8 return $value;
86 },
87 set => sub {
88 6 ▶ my $value = shift;
Subroutine __ANON__: called CC=2 SCAR=9.2
89 # do some caller() magic to warn at the right place
90 6 ▶ if ( !ref $object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $object) 0 6 6
91 0 my @c = caller(2);
92 0 my ( $filename, $line ) = @c[ 1, 2 ];
93 0 warn qq{Useless attempt to set a value on a non-reference at $filename line $line\n};
94 }
95 6 $self->set( $object, $value, 1 );
96 },
97 13 );
98 }
99  
100 sub values {
101 27 ▶ my ( $self, $object ) = @_;
Subroutine values: called CC=3 SCAR=11.0
Pod documented
102 27 ▶ croak q{non-safe evaluation, died} if "$self" =~ /\?\(/ && $JSON::Path::Safe;
Branch: 1 branch
BranchTrueFalseTotal
if "$self" =~ /\?\(/ and $JSON::Path::Safe 1 26 27
Condition100%3/3
"$self" =~ /\?\(/ and $JSON::Path::Safe
!ll&&!rl&&r
2511
MC/DC100%2/2
"$self" =~ /\?\(/ and $JSON::Path::Safe
"$self" =~ /\?\(/ $JSON::Path::Safe
Truth table100%3/3
A and B
A= "$self" =~ /\?\(/B= $JSON::Path::Safe
ABresult
0X0
100
111
103  
104 26 return JSON::Path::Evaluator::evaluate_jsonpath( $object, "$self", script_engine => 'perl' );
105 }
106  
107 sub map {
108 1 ▶ my ( $self, $object, $coderef ) = @_;
Subroutine map: called CC=2 SCAR=6.9
Pod documented
109 1 my $count;
110 1 foreach my $path ( $self->paths( $object ) ) {
111 4 my ($ref) = JSON::Path::Evaluator::evaluate_jsonpath( $object, $path, want_ref => 1 );
112 4 ++$count;
113 4 my $value = do {
114 13 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
115 4 local $_ = ${$ref};
116 4 local $. = $path;
117 4 scalar $coderef->();
118 };
119 4 ${$ref} = $value;
120 }
121 1 return $count;
122 }
123  
124 13 1;
125  
126 __END__
« Path/Tokenizer.pm ↑ Summary Path/Constants.pm »