Path.pm

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