line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jmespath; |
2
|
2
|
|
|
2
|
|
11222
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
44
|
|
3
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
38
|
|
4
|
2
|
|
|
2
|
|
356
|
use Jmespath::Parser; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
47
|
|
5
|
2
|
|
|
2
|
|
290
|
use Jmespath::Visitor; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
56
|
|
6
|
2
|
|
|
2
|
|
543
|
use JSON qw(encode_json decode_json); |
|
2
|
|
|
|
|
11049
|
|
|
2
|
|
|
|
|
11
|
|
7
|
2
|
|
|
2
|
|
262
|
use Try::Tiny; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
137
|
|
8
|
2
|
|
|
2
|
|
19
|
use v5.14; |
|
2
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
10
|
2
|
|
|
2
|
|
490
|
use utf8; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
9
|
|
11
|
2
|
|
|
2
|
|
1092
|
use Encode; |
|
2
|
|
|
|
|
13821
|
|
|
2
|
|
|
|
|
595
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub compile { |
14
|
0
|
|
|
0
|
0
|
0
|
my ( $class, $expression ) = @_; |
15
|
0
|
|
|
|
|
0
|
return Jmespath::Parser->new->parse( Encode::encode_utf8($expression) ); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub search { |
19
|
861
|
|
|
861
|
0
|
382249
|
my ( $class, $expression, $data, $options ) = @_; |
20
|
861
|
|
|
|
|
828
|
my ($result); |
21
|
|
|
|
|
|
|
try { |
22
|
861
|
|
|
861
|
|
15306
|
$result = Jmespath::Parser->new->parse( $expression ) |
23
|
|
|
|
|
|
|
->search( $data, $options ); |
24
|
|
|
|
|
|
|
} catch { |
25
|
146
|
|
|
146
|
|
2960
|
$_->throw; |
26
|
861
|
|
|
|
|
3206
|
}; |
27
|
715
|
100
|
|
|
|
9260
|
return $result if not defined $result; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# JSON block result |
30
|
631
|
100
|
100
|
|
|
2388
|
if ( ( ref ($result) eq 'HASH' ) or |
31
|
|
|
|
|
|
|
( ref ($result) eq 'ARRAY' ) ) { |
32
|
|
|
|
|
|
|
try { |
33
|
312
|
|
|
312
|
|
7748
|
$result = JSON->new |
34
|
|
|
|
|
|
|
->utf8(1) |
35
|
|
|
|
|
|
|
->allow_nonref |
36
|
|
|
|
|
|
|
->space_after |
37
|
|
|
|
|
|
|
->allow_blessed(1) |
38
|
|
|
|
|
|
|
->convert_blessed(1) |
39
|
|
|
|
|
|
|
->encode( $result ); |
40
|
312
|
|
|
|
|
885
|
return $result; |
41
|
|
|
|
|
|
|
} catch { |
42
|
0
|
|
|
0
|
|
0
|
Jmespath::ValueException->new( message => "cannot encode" )->throw; |
43
|
312
|
|
|
|
|
1301
|
}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
631
|
100
|
|
|
|
4076
|
if ( $result =~ /[0-9]+/ ) { |
47
|
381
|
|
|
|
|
1779
|
return $result; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Unquoted string result |
51
|
250
|
50
|
33
|
|
|
903
|
if ( $ENV{JP_UNQUOTED} == 0 or |
52
|
|
|
|
|
|
|
not defined $ENV{JP_UNQUOTED} ) { |
53
|
0
|
|
|
|
|
0
|
$result = q{"} . $result . q{"}; |
54
|
|
|
|
|
|
|
} |
55
|
250
|
|
|
|
|
577
|
return $result; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 NAME |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Jmespath - Enabling easy querying for JSON structures. |
65
|
|
|
|
|
|
|
|