| 1 | package Jmespath; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Jmespath::Parser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Jmespath::Visitor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use JSON qw(encode_json decode_json); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use v5.14; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 10 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub compile { | ||||||||||||||||||||||||||
|
Subroutine
compile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 0 | my ( $class, $expression ) = @_; | |||||||||||||||||||||||||||
| 15 | 0 | return Jmespath::Parser->new->parse( Encode::encode_utf8($expression) ); | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 861 | ▶ | sub search { | ||||||||||||||||||||||||||
|
Subroutine
search: called CC=7 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 861 | my ( $class, $expression, $data, $options ) = @_; | |||||||||||||||||||||||||||
| 20 | 861 | my ($result); | |||||||||||||||||||||||||||
| 21 | 861 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 861 | $result = Jmespath::Parser->new->parse( $expression ) | |||||||||||||||||||||||||||
| 23 | ->search( $data, $options ); | ||||||||||||||||||||||||||||
| 24 | 146 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 146 | $_->throw; | |||||||||||||||||||||||||||
| 26 | 861 | }; | |||||||||||||||||||||||||||
| 27 | 715 | ▶ | return $result if not defined $result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # JSON block result | ||||||||||||||||||||||||||||
| 30 | 631 | ▶ | if ( ( ref ($result) eq 'HASH' ) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $result eq "HASH" or ref $result eq "ARRAY"
MC/DC100%2/2
ref $result eq "HASH" or ref $result eq "ARRAY"
ref $result eq "HASH"
ref $result eq "ARRAY"
Truth table100%3/3
A or B
A= ref $result eq "HASH"B= ref $result eq "ARRAY"
| |||||||||||||||||||||||||||||
| 31 | ( ref ($result) eq 'ARRAY' ) ) { | ||||||||||||||||||||||||||||
| 32 | 312 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 312 | $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 | return $result; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 42 | 0 | Jmespath::ValueException->new( message => "cannot encode" )->throw; | |||||||||||||||||||||||||||
| 43 | 312 | }; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 631 | ▶ | if ( $result =~ /[0-9]+/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 381 | return $result; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # Unquoted string result | ||||||||||||||||||||||||||||
| 51 | 250 | ▶ | if ( $ENV{JP_UNQUOTED} == 0 or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ENV{"JP_UNQUOTED"} == 0 or not defined $ENV{"JP_UNQUOTED"}
MC/DC0%0/2
$ENV{"JP_UNQUOTED"} == 0 or not defined $ENV{"JP_UNQUOTED"}
$ENV{"JP_UNQUOTED"} == 0
not defined $ENV{"JP_UNQUOTED"}
Truth table33%1/3
A or not(B)
A= $ENV{"JP_UNQUOTED"} == 0B= not defined $ENV{"JP_UNQUOTED"}
| |||||||||||||||||||||||||||||
| 52 | not defined $ENV{JP_UNQUOTED} ) { | ||||||||||||||||||||||||||||
| 53 | 0 | $result = q{"} . $result . q{"}; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 250 | return $result; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | 1; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||