line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
13
|
|
|
13
|
|
1785161
|
use 5.008; |
|
13
|
|
|
|
|
153
|
|
2
|
13
|
|
|
13
|
|
71
|
use strict; |
|
13
|
|
|
|
|
21
|
|
|
13
|
|
|
|
|
280
|
|
3
|
13
|
|
|
13
|
|
59
|
use warnings; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
833
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package JSON::Path; |
6
|
|
|
|
|
|
|
$JSON::Path::VERSION = '0.431'; |
7
|
|
|
|
|
|
|
# VERSION |
8
|
|
|
|
|
|
|
|
9
|
13
|
|
|
13
|
|
6296
|
use Exporter::Tiny (); |
|
13
|
|
|
|
|
40047
|
|
|
13
|
|
|
|
|
625
|
|
10
|
|
|
|
|
|
|
our @ISA = qw/ Exporter::Tiny /; |
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:POPEFELIX'; |
12
|
|
|
|
|
|
|
our $Safe = 1; |
13
|
|
|
|
|
|
|
|
14
|
13
|
|
|
13
|
|
93
|
use Carp; |
|
13
|
|
|
|
|
27
|
|
|
13
|
|
|
|
|
758
|
|
15
|
13
|
|
|
13
|
|
5960
|
use JSON::MaybeXS qw/decode_json/; |
|
13
|
|
|
|
|
87384
|
|
|
13
|
|
|
|
|
716
|
|
16
|
13
|
|
|
13
|
|
6690
|
use JSON::Path::Evaluator; |
|
13
|
|
|
|
|
47
|
|
|
13
|
|
|
|
|
742
|
|
17
|
13
|
|
|
13
|
|
87
|
use Scalar::Util qw[blessed]; |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
571
|
|
18
|
13
|
|
|
13
|
|
5744
|
use LV (); |
|
13
|
|
|
|
|
47178
|
|
|
13
|
|
|
|
|
630
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ jpath jpath1 jpath_map /; |
21
|
|
|
|
|
|
|
|
22
|
13
|
|
|
13
|
|
100
|
use overload '""' => \&to_string; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
128
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub jpath { |
25
|
3
|
|
|
3
|
1
|
9
|
my ( $object, $expression ) = @_; |
26
|
3
|
|
|
|
|
11
|
my @return = __PACKAGE__->new($expression)->values($object); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub jpath1 : lvalue { |
30
|
4
|
|
|
4
|
1
|
1530
|
my ( $object, $expression ) = @_; |
31
|
4
|
|
|
|
|
19
|
__PACKAGE__->new($expression)->value($object); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub jpath_map (&$$) { |
35
|
1
|
|
|
1
|
1
|
168
|
my ( $coderef, $object, $expression ) = @_; |
36
|
1
|
|
|
|
|
6
|
return __PACKAGE__->new($expression)->map( $object, $coderef ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new { |
40
|
32
|
|
|
32
|
1
|
9351
|
my ( $class, $expression ) = @_; |
41
|
32
|
50
|
33
|
|
|
154
|
return $expression |
42
|
|
|
|
|
|
|
if blessed($expression) && $expression->isa(__PACKAGE__); |
43
|
32
|
|
|
|
|
116
|
return bless \$expression, $class; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub to_string { |
47
|
71
|
|
|
71
|
1
|
219
|
my ($self) = @_; |
48
|
71
|
|
|
|
|
518
|
return $$self; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub paths { |
52
|
6
|
|
|
6
|
1
|
1373
|
my ( $self, $object ) = @_; |
53
|
6
|
|
|
|
|
148
|
my @paths = JSON::Path::Evaluator::evaluate_jsonpath( $object, "$self", want_path => 1); |
54
|
6
|
|
|
|
|
27
|
return @paths; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub get { |
58
|
9
|
|
|
9
|
1
|
30
|
my ( $self, $object ) = @_; |
59
|
9
|
|
|
|
|
26
|
my @values = $self->values($object); |
60
|
9
|
100
|
|
|
|
35
|
return wantarray ? @values : $values[0]; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub set { |
64
|
10
|
|
|
10
|
1
|
544
|
my ( $self, $object, $value, $limit ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
10
|
50
|
|
|
|
44
|
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
|
|
|
|
|
17
|
my $count = 0; |
74
|
10
|
|
|
|
|
62
|
my @refs = JSON::Path::Evaluator::evaluate_jsonpath( $object, "$self", want_ref => 1 ); |
75
|
10
|
|
|
|
|
29
|
for my $ref (@refs) { |
76
|
12
|
|
|
|
|
18
|
${$ref} = $value; |
|
12
|
|
|
|
|
22
|
|
77
|
12
|
|
|
|
|
19
|
++$count; |
78
|
12
|
100
|
100
|
|
|
51
|
last if $limit && ( $count >= $limit ); |
79
|
|
|
|
|
|
|
} |
80
|
10
|
|
|
|
|
37
|
return $count; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub value : lvalue { |
84
|
13
|
|
|
13
|
1
|
6659
|
my ( $self, $object ) = @_; |
85
|
|
|
|
|
|
|
LV::lvalue( |
86
|
|
|
|
|
|
|
get => sub { |
87
|
8
|
|
|
8
|
|
227
|
my ($value) = $self->get($object); |
88
|
8
|
|
|
|
|
60
|
return $value; |
89
|
|
|
|
|
|
|
}, |
90
|
|
|
|
|
|
|
set => sub { |
91
|
6
|
|
|
6
|
|
79
|
my $value = shift; |
92
|
|
|
|
|
|
|
# do some caller() magic to warn at the right place |
93
|
6
|
50
|
|
|
|
18
|
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
|
|
|
|
|
17
|
$self->set( $object, $value, 1 ); |
99
|
|
|
|
|
|
|
}, |
100
|
13
|
|
|
|
|
140
|
); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub values { |
104
|
27
|
|
|
27
|
1
|
1374
|
my ( $self, $object ) = @_; |
105
|
27
|
100
|
100
|
|
|
266
|
croak q{non-safe evaluation, died} if "$self" =~ /\?\(/ && $JSON::Path::Safe; |
106
|
|
|
|
|
|
|
|
107
|
26
|
|
|
|
|
55
|
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
|
|
|
|
|
1
|
my $count; |
113
|
1
|
|
|
|
|
4
|
foreach my $path ( $self->paths( $object ) ) { |
114
|
4
|
|
|
|
|
9
|
my ($ref) = JSON::Path::Evaluator::evaluate_jsonpath( $object, $path, want_ref => 1 ); |
115
|
4
|
|
|
|
|
5
|
++$count; |
116
|
4
|
|
|
|
|
5
|
my $value = do { |
117
|
13
|
|
|
13
|
|
10005
|
no warnings 'numeric'; |
|
13
|
|
|
|
|
30
|
|
|
13
|
|
|
|
|
1511
|
|
118
|
4
|
|
|
|
|
5
|
local $_ = ${$ref}; |
|
4
|
|
|
|
|
8
|
|
119
|
4
|
|
|
|
|
11
|
local $. = $path; |
120
|
4
|
|
|
|
|
16
|
scalar $coderef->(); |
121
|
|
|
|
|
|
|
}; |
122
|
4
|
|
|
|
|
16
|
${$ref} = $value; |
|
4
|
|
|
|
|
7
|
|
123
|
|
|
|
|
|
|
} |
124
|
1
|
|
|
|
|
4
|
return $count; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |