line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
13
|
|
|
13
|
|
1724412
|
use 5.008; |
|
13
|
|
|
|
|
147
|
|
2
|
13
|
|
|
13
|
|
65
|
use strict; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
254
|
|
3
|
13
|
|
|
13
|
|
58
|
use warnings; |
|
13
|
|
|
|
|
22
|
|
|
13
|
|
|
|
|
654
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package JSON::Path; |
6
|
|
|
|
|
|
|
$JSON::Path::VERSION = '0.430'; |
7
|
|
|
|
|
|
|
# VERSION |
8
|
|
|
|
|
|
|
|
9
|
13
|
|
|
13
|
|
6403
|
use Exporter::Tiny (); |
|
13
|
|
|
|
|
40919
|
|
|
13
|
|
|
|
|
644
|
|
10
|
|
|
|
|
|
|
our @ISA = qw/ Exporter::Tiny /; |
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:POPEFELIX'; |
12
|
|
|
|
|
|
|
our $Safe = 1; |
13
|
|
|
|
|
|
|
|
14
|
13
|
|
|
13
|
|
97
|
use Carp; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
761
|
|
15
|
13
|
|
|
13
|
|
6056
|
use JSON::MaybeXS qw/decode_json/; |
|
13
|
|
|
|
|
89850
|
|
|
13
|
|
|
|
|
763
|
|
16
|
13
|
|
|
13
|
|
6739
|
use JSON::Path::Evaluator; |
|
13
|
|
|
|
|
48
|
|
|
13
|
|
|
|
|
746
|
|
17
|
13
|
|
|
13
|
|
89
|
use Scalar::Util qw[blessed]; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
570
|
|
18
|
13
|
|
|
13
|
|
5973
|
use LV (); |
|
13
|
|
|
|
|
47560
|
|
|
13
|
|
|
|
|
750
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ jpath jpath1 jpath_map /; |
21
|
|
|
|
|
|
|
|
22
|
13
|
|
|
13
|
|
94
|
use overload '""' => \&to_string; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
124
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub jpath { |
25
|
3
|
|
|
3
|
1
|
10
|
my ( $object, $expression ) = @_; |
26
|
3
|
|
|
|
|
11
|
my @return = __PACKAGE__->new($expression)->values($object); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub jpath1 : lvalue { |
30
|
4
|
|
|
4
|
1
|
1264
|
my ( $object, $expression ) = @_; |
31
|
4
|
|
|
|
|
17
|
__PACKAGE__->new($expression)->value($object); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub jpath_map (&$$) { |
35
|
1
|
|
|
1
|
1
|
195
|
my ( $coderef, $object, $expression ) = @_; |
36
|
1
|
|
|
|
|
6
|
return __PACKAGE__->new($expression)->map( $object, $coderef ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new { |
40
|
32
|
|
|
32
|
1
|
9519
|
my ( $class, $expression ) = @_; |
41
|
32
|
50
|
33
|
|
|
161
|
return $expression |
42
|
|
|
|
|
|
|
if blessed($expression) && $expression->isa(__PACKAGE__); |
43
|
32
|
|
|
|
|
119
|
return bless \$expression, $class; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub to_string { |
47
|
71
|
|
|
71
|
1
|
204
|
my ($self) = @_; |
48
|
71
|
|
|
|
|
529
|
return $$self; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub paths { |
52
|
6
|
|
|
6
|
1
|
1447
|
my ( $self, $object ) = @_; |
53
|
6
|
|
|
|
|
167
|
my @paths = JSON::Path::Evaluator::evaluate_jsonpath( $object, "$self", want_path => 1); |
54
|
6
|
|
|
|
|
28
|
return @paths; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub get { |
58
|
9
|
|
|
9
|
1
|
26
|
my ( $self, $object ) = @_; |
59
|
9
|
|
|
|
|
27
|
my @values = $self->values($object); |
60
|
9
|
100
|
|
|
|
37
|
return wantarray ? @values : $values[0]; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub set { |
64
|
10
|
|
|
10
|
1
|
658
|
my ( $self, $object, $value, $limit ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
10
|
50
|
|
|
|
26
|
if ( !ref $object ) { |
67
|
|
|
|
|
|
|
# warn if not called internally. If called internally (i.e. from value()) we will already have warned. |
68
|
0
|
|
|
|
|
0
|
my @c = caller(0); |
69
|
0
|
0
|
|
|
|
0
|
if ( $c[1] !~ /JSON\/Path\.pm$/ ) { |
70
|
0
|
|
|
|
|
0
|
carp qq{Useless attempt to set a value on a non-reference}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
10
|
|
|
|
|
30
|
my $count = 0; |
74
|
10
|
|
|
|
|
57
|
my @refs = JSON::Path::Evaluator::evaluate_jsonpath( $object, "$self", want_ref => 1 ); |
75
|
10
|
|
|
|
|
25
|
for my $ref (@refs) { |
76
|
12
|
|
|
|
|
18
|
${$ref} = $value; |
|
12
|
|
|
|
|
20
|
|
77
|
12
|
|
|
|
|
22
|
++$count; |
78
|
12
|
100
|
100
|
|
|
46
|
last if $limit && ( $count >= $limit ); |
79
|
|
|
|
|
|
|
} |
80
|
10
|
|
|
|
|
38
|
return $count; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub value : lvalue { |
84
|
13
|
|
|
13
|
1
|
6365
|
my ( $self, $object ) = @_; |
85
|
|
|
|
|
|
|
LV::lvalue( |
86
|
|
|
|
|
|
|
get => sub { |
87
|
8
|
|
|
8
|
|
179
|
my ($value) = $self->get($object); |
88
|
8
|
|
|
|
|
48
|
return $value; |
89
|
|
|
|
|
|
|
}, |
90
|
|
|
|
|
|
|
set => sub { |
91
|
6
|
|
|
6
|
|
66
|
my $value = shift; |
92
|
|
|
|
|
|
|
# do some caller() magic to warn at the right place |
93
|
6
|
50
|
|
|
|
15
|
if ( !ref $object ) { |
94
|
0
|
|
|
|
|
0
|
my @c = caller(2); |
95
|
0
|
|
|
|
|
0
|
my ( $filename, $line ) = @c[ 1, 2 ]; |
96
|
0
|
|
|
|
|
0
|
warn qq{Useless attempt to set a value on a non-reference at $filename line $line\n}; |
97
|
|
|
|
|
|
|
} |
98
|
6
|
|
|
|
|
16
|
$self->set( $object, $value, 1 ); |
99
|
|
|
|
|
|
|
}, |
100
|
13
|
|
|
|
|
108
|
); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub values { |
104
|
27
|
|
|
27
|
1
|
1313
|
my ( $self, $object ) = @_; |
105
|
27
|
100
|
100
|
|
|
284
|
croak q{non-safe evaluation, died} if "$self" =~ /\?\(/ && $JSON::Path::Safe; |
106
|
|
|
|
|
|
|
|
107
|
26
|
|
|
|
|
63
|
return JSON::Path::Evaluator::evaluate_jsonpath( $object, "$self", script_engine => 'perl' ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub map { |
111
|
1
|
|
|
1
|
1
|
3
|
my ( $self, $object, $coderef ) = @_; |
112
|
1
|
|
|
|
|
2
|
my $count; |
113
|
1
|
|
|
|
|
4
|
foreach my $path ( $self->paths( $object ) ) { |
114
|
4
|
|
|
|
|
18
|
my ($ref) = JSON::Path::Evaluator::evaluate_jsonpath( $object, $path, want_ref => 1 ); |
115
|
4
|
|
|
|
|
8
|
++$count; |
116
|
4
|
|
|
|
|
6
|
my $value = do { |
117
|
13
|
|
|
13
|
|
10045
|
no warnings 'numeric'; |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
1548
|
|
118
|
4
|
|
|
|
|
6
|
local $_ = ${$ref}; |
|
4
|
|
|
|
|
7
|
|
119
|
4
|
|
|
|
|
14
|
local $. = $path; |
120
|
4
|
|
|
|
|
21
|
scalar $coderef->(); |
121
|
|
|
|
|
|
|
}; |
122
|
4
|
|
|
|
|
20
|
${$ref} = $value; |
|
4
|
|
|
|
|
12
|
|
123
|
|
|
|
|
|
|
} |
124
|
1
|
|
|
|
|
3
|
return $count; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |