| 1 | package Jmespath::Functions; | ||||||||||||||||||||||||||||||||||
| 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 parent 'Exporter'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use POSIX qw(ceil floor); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Jmespath::Expression; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Jmespath::ValueException; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Jmespath::JMESPathTypeException; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Jmespath::String; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Scalar::Util qw(looks_like_number isdual blessed); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use v5.12; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 2 | our @EXPORT_OK = qw( jp_abs | |||||||||||||||||||||||||||||||||
| 16 | jp_avg | ||||||||||||||||||||||||||||||||||
| 17 | jp_contains | ||||||||||||||||||||||||||||||||||
| 18 | jp_ceil | ||||||||||||||||||||||||||||||||||
| 19 | jp_ends_with | ||||||||||||||||||||||||||||||||||
| 20 | jp_eq | ||||||||||||||||||||||||||||||||||
| 21 | jp_floor | ||||||||||||||||||||||||||||||||||
| 22 | jp_gt | ||||||||||||||||||||||||||||||||||
| 23 | jp_gte | ||||||||||||||||||||||||||||||||||
| 24 | jp_join | ||||||||||||||||||||||||||||||||||
| 25 | jp_keys | ||||||||||||||||||||||||||||||||||
| 26 | jp_length | ||||||||||||||||||||||||||||||||||
| 27 | jp_lt | ||||||||||||||||||||||||||||||||||
| 28 | jp_lte | ||||||||||||||||||||||||||||||||||
| 29 | jp_map | ||||||||||||||||||||||||||||||||||
| 30 | jp_max | ||||||||||||||||||||||||||||||||||
| 31 | jp_max_by | ||||||||||||||||||||||||||||||||||
| 32 | jp_merge | ||||||||||||||||||||||||||||||||||
| 33 | jp_min | ||||||||||||||||||||||||||||||||||
| 34 | jp_min_by | ||||||||||||||||||||||||||||||||||
| 35 | jp_ne | ||||||||||||||||||||||||||||||||||
| 36 | jp_not_null | ||||||||||||||||||||||||||||||||||
| 37 | jp_reverse | ||||||||||||||||||||||||||||||||||
| 38 | jp_sort | ||||||||||||||||||||||||||||||||||
| 39 | jp_sort_by | ||||||||||||||||||||||||||||||||||
| 40 | jp_starts_with | ||||||||||||||||||||||||||||||||||
| 41 | jp_sum | ||||||||||||||||||||||||||||||||||
| 42 | jp_to_array | ||||||||||||||||||||||||||||||||||
| 43 | jp_to_string | ||||||||||||||||||||||||||||||||||
| 44 | jp_to_number | ||||||||||||||||||||||||||||||||||
| 45 | jp_type | ||||||||||||||||||||||||||||||||||
| 46 | jp_values ); | ||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | 2 | our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); | |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | # jp_abs | ||||||||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||||||||
| 52 | # Absolute value of provided value. Throws exception if value is not | ||||||||||||||||||||||||||||||||||
| 53 | # a signed integer. | ||||||||||||||||||||||||||||||||||
| 54 | 10 | ▶ | sub jp_abs { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_abs: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 55 | 10 | my @args = @_; | |||||||||||||||||||||||||||||||||
| 56 | 10 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @args < 1 or scalar @args > 1
MC/DC100%2/2
scalar @args < 1 or scalar @args > 1
scalar @args < 1
scalar @args > 1
Truth table100%3/3
A or B
A= scalar @args < 1B= scalar @args > 1
| |||||||||||||||||||||||||||||||||||
| 57 | ->new({ message => 'abs() requires one argument' }) | ||||||||||||||||||||||||||||||||||
| 58 | ->throw | ||||||||||||||||||||||||||||||||||
| 59 | if scalar @args < 1 or scalar @args > 1; | ||||||||||||||||||||||||||||||||||
| 60 | 8 | my $arg = shift @args; | |||||||||||||||||||||||||||||||||
| 61 | 8 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 62 | ->new({ message => 'contains() illegal boolean value' }) | ||||||||||||||||||||||||||||||||||
| 63 | ->throw | ||||||||||||||||||||||||||||||||||
| 64 | if JSON::is_bool($arg); | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | 7 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 67 | ->new({ message => 'Not a number: [' . $arg . ']'}) | ||||||||||||||||||||||||||||||||||
| 68 | ->throw | ||||||||||||||||||||||||||||||||||
| 69 | if not looks_like_number($arg); | ||||||||||||||||||||||||||||||||||
| 70 | 6 | return abs($arg); | |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 6 | ▶ | sub jp_avg { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_avg: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 74 | 6 | my ($values) = @_; | |||||||||||||||||||||||||||||||||
| 75 | 6 | ▶ | Jmespath::ValueException->new({ message => 'Required argument not array ref' })->throw | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 76 | if ref $values ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | 3 | foreach (@$values) { | |||||||||||||||||||||||||||||||||
| 79 | 10 | ▶ | Jmespath::ValueException->new({ message => 'Not a number: ' . $_ })->throw | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | if not looks_like_number($_); | ||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||
| 82 | 1 | return jp_sum($values) / scalar(@$values); | |||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 6 | ▶ | sub jp_contains { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_contains: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 87 | 6 | my ( $subject, $search ) = @_; | |||||||||||||||||||||||||||||||||
| 88 | 6 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 89 | ->new({ message => 'contains() illegal boolean value' }) | ||||||||||||||||||||||||||||||||||
| 90 | ->throw | ||||||||||||||||||||||||||||||||||
| 91 | if JSON::is_bool($subject); | ||||||||||||||||||||||||||||||||||
| 92 | 5 | ▶ | if ( ref $subject eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 93 | 3 | foreach (@$subject) { | |||||||||||||||||||||||||||||||||
| 94 | 6 | ▶ | return JSON::true if ( $_ eq $search ); #must be exact string match | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | 1 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||
| 98 | elsif ( ref $subject eq '' ) { # straight string | ||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | return JSON::true if $subject =~ /$search/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||
| 101 | 1 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | 5 | ▶ | sub jp_ceil { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_ceil: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 106 | 5 | my ($value) = @_; | |||||||||||||||||||||||||||||||||
| 107 | 5 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 108 | ->new({ message => 'ceil() requires one argument' }) | ||||||||||||||||||||||||||||||||||
| 109 | ->throw | ||||||||||||||||||||||||||||||||||
| 110 | if not defined $value; | ||||||||||||||||||||||||||||||||||
| 111 | 5 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 112 | ->new({ message => 'ceil() requires one number' }) | ||||||||||||||||||||||||||||||||||
| 113 | ->throw | ||||||||||||||||||||||||||||||||||
| 114 | if not looks_like_number($value); | ||||||||||||||||||||||||||||||||||
| 115 | 4 | return ceil($value); | |||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | 6 | ▶ | sub jp_ends_with { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_ends_with: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 119 | 6 | my ( $subject, $suffix ) = @_; | |||||||||||||||||||||||||||||||||
| 120 | 6 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 121 | ->new({ message => 'ends_with() allows strings only' }) | ||||||||||||||||||||||||||||||||||
| 122 | ->throw | ||||||||||||||||||||||||||||||||||
| 123 | if looks_like_number($suffix); | ||||||||||||||||||||||||||||||||||
| 124 | 5 | ▶ | return JSON::true if $subject =~ /$suffix$/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 125 | 2 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | 288 | ▶ | sub jp_eq { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_eq: called CC=26 SCAR=32.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 129 | 288 | my ($left, $right) = @_; | |||||||||||||||||||||||||||||||||
| 130 | 288 | ▶ | return JSON::true if not defined $left and not defined $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $left or defined $right
MC/DC100%2/2
defined $left or defined $right
defined $left
defined $right
Truth table100%3/3
A or B
A= defined $leftB= defined $right
| |||||||||||||||||||||||||||||||||||
| 131 | 284 | ▶ | return JSON::false if not defined $left or not defined $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $left and defined $right
MC/DC100%2/2
defined $left and defined $right
defined $left
defined $right
Truth table100%3/3
A and B
A= defined $leftB= defined $right
| |||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | # If $left or $right is a boolean, they both must be boolean | ||||||||||||||||||||||||||||||||||
| 134 | 239 | ▶ | if (ref($left) eq 'JSON::PP::Boolean' or | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "JSON::PP::Boolean" or ref $right eq "JSON::PP::Boolean"
MC/DC100%2/2
ref $left eq "JSON::PP::Boolean" or ref $right eq "JSON::PP::Boolean"
ref $left eq "JSON::PP::Boolean"
ref $right eq "JSON::PP::Boolean"
Truth table100%3/3
A or B
A= ref $left eq "JSON::PP::Boolean"B= ref $right eq "JSON::PP::Boolean"
| |||||||||||||||||||||||||||||||||||
| 135 | ref($right) eq 'JSON::PP::Boolean') { | ||||||||||||||||||||||||||||||||||
| 136 | 56 | ▶ | if (ref($left) eq 'JSON::PP::Boolean' and | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "JSON::PP::Boolean" and ref $right eq "JSON::PP::Boolean"
MC/DC100%2/2
ref $left eq "JSON::PP::Boolean" and ref $right eq "JSON::PP::Boolean"
ref $left eq "JSON::PP::Boolean"
ref $right eq "JSON::PP::Boolean"
Truth table100%3/3
A and B
A= ref $left eq "JSON::PP::Boolean"B= ref $right eq "JSON::PP::Boolean"
| |||||||||||||||||||||||||||||||||||
| 137 | ref($right) eq 'JSON::PP::Boolean' ) { | ||||||||||||||||||||||||||||||||||
| 138 | 8 | ▶ | return JSON::true if $left == $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 139 | 4 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||
| 141 | 48 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | #If $left or $right is a HASH or ARRAY reference, they need to be | ||||||||||||||||||||||||||||||||||
| 145 | #compared because comparison of json objects must be handled. | ||||||||||||||||||||||||||||||||||
| 146 | 183 | ▶ | if (ref($left) eq 'HASH' or ref($right) eq 'HASH') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "HASH" or ref $right eq "HASH"
MC/DC100%2/2
ref $left eq "HASH" or ref $right eq "HASH"
ref $left eq "HASH"
ref $right eq "HASH"
Truth table100%3/3
A or B
A= ref $left eq "HASH"B= ref $right eq "HASH"
| |||||||||||||||||||||||||||||||||||
| 147 | 43 | ▶ | if (ref($left) eq 'HASH' and ref($right) eq 'HASH') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "HASH" and ref $right eq "HASH"
MC/DC100%2/2
ref $left eq "HASH" and ref $right eq "HASH"
ref $left eq "HASH"
ref $right eq "HASH"
Truth table100%3/3
A and B
A= ref $left eq "HASH"B= ref $right eq "HASH"
| |||||||||||||||||||||||||||||||||||
| 148 | 11 | ▶ | return JSON::true if hashes_equal($left, $right); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||
| 150 | 38 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 140 | ▶ | if (ref($left) eq 'ARRAY' or ref($right) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "ARRAY" or ref $right eq "ARRAY"
MC/DC100%2/2
ref $left eq "ARRAY" or ref $right eq "ARRAY"
ref $left eq "ARRAY"
ref $right eq "ARRAY"
Truth table100%3/3
A or B
A= ref $left eq "ARRAY"B= ref $right eq "ARRAY"
| |||||||||||||||||||||||||||||||||||
| 154 | 24 | ▶ | if (ref($left) eq 'ARRAY' and ref($right) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "ARRAY" and ref $right eq "ARRAY"
MC/DC100%2/2
ref $left eq "ARRAY" and ref $right eq "ARRAY"
ref $left eq "ARRAY"
ref $right eq "ARRAY"
Truth table100%3/3
A and B
A= ref $left eq "ARRAY"B= ref $right eq "ARRAY"
| |||||||||||||||||||||||||||||||||||
| 155 | 8 | ▶ | return JSON::true if arrays_equal($left, $right); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||
| 157 | 20 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||
| 160 | 116 | ▶ | if (looks_like_number($left) and | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
&looks_like_number($left) and &looks_like_number($right)
MC/DC50%1/2
&looks_like_number($left) and &looks_like_number($right)
&looks_like_number($left)
&looks_like_number($right)
Truth table66%2/3
A and B
A= &looks_like_number($left)B= &looks_like_number($right)
| |||||||||||||||||||||||||||||||||||
| 161 | looks_like_number($right)) { | ||||||||||||||||||||||||||||||||||
| 162 | 87 | ▶ | return JSON::true if $left == $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||
| 164 | ▶ | elsif (not looks_like_number($left) and | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
&looks_like_number($left) || &looks_like_number($right)
MC/DC0%0/2
&looks_like_number($left) || &looks_like_number($right)
&looks_like_number($left)
&looks_like_number($right)
Truth table33%1/3
A || B
A= &looks_like_number($left)B= &looks_like_number($right)
| |||||||||||||||||||||||||||||||||||
| 165 | not looks_like_number($right)) { | ||||||||||||||||||||||||||||||||||
| 166 | 29 | ▶ | return JSON::true if $left eq $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||
| 168 | 55 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||
| 171 | 5 | ▶ | sub jp_floor { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_floor: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 172 | 5 | my ($value) = @_; | |||||||||||||||||||||||||||||||||
| 173 | 5 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 174 | ->new({ message => 'floor() requires one argument' }) | ||||||||||||||||||||||||||||||||||
| 175 | ->throw | ||||||||||||||||||||||||||||||||||
| 176 | if not defined $value; | ||||||||||||||||||||||||||||||||||
| 177 | 5 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 178 | ->new({ message => 'floor() requires one number' }) | ||||||||||||||||||||||||||||||||||
| 179 | ->throw | ||||||||||||||||||||||||||||||||||
| 180 | if not looks_like_number($value); | ||||||||||||||||||||||||||||||||||
| 181 | 3 | return floor($value); | |||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||
| 185 | 18 | ▶ | sub jp_gt { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_gt: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 186 | 18 | my ($left, $right) = @_; | |||||||||||||||||||||||||||||||||
| 187 | # According to the JMESPath Specification, this function returns | ||||||||||||||||||||||||||||||||||
| 188 | # undef if the variants are not numbers. | ||||||||||||||||||||||||||||||||||
| 189 | 18 | ▶ | return if not looks_like_number($left); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 190 | 18 | ▶ | return if not looks_like_number($right); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 191 | 18 | ▶ | return JSON::true if $left > $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 192 | 11 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | 4 | ▶ | sub jp_gte { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_gte: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 196 | 4 | my ($left, $right) = @_; | |||||||||||||||||||||||||||||||||
| 197 | # According to the JMESPath Specification, this function returns | ||||||||||||||||||||||||||||||||||
| 198 | # undef if the variants are not numbers. | ||||||||||||||||||||||||||||||||||
| 199 | 4 | ▶ | return if not looks_like_number($left); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 200 | 4 | ▶ | return if not looks_like_number($right); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 201 | 4 | ▶ | return JSON::true if $left >= $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 202 | 2 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||
| 205 | 22 | ▶ | sub jp_lt { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_lt: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 206 | 22 | my ($left, $right) = @_; | |||||||||||||||||||||||||||||||||
| 207 | # According to the JMESPath Specification, this function returns | ||||||||||||||||||||||||||||||||||
| 208 | # undef if the variants are not numbers. | ||||||||||||||||||||||||||||||||||
| 209 | 22 | ▶ | return if not looks_like_number($left); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 210 | 22 | ▶ | return if not looks_like_number($right); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 211 | 22 | ▶ | return JSON::true if $left < $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 212 | 12 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||
| 215 | 4 | ▶ | sub jp_lte { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_lte: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 216 | 4 | my ($left, $right) = @_; | |||||||||||||||||||||||||||||||||
| 217 | # According to the JMESPath Specification, this function returns | ||||||||||||||||||||||||||||||||||
| 218 | # undef if the variants are not numbers. | ||||||||||||||||||||||||||||||||||
| 219 | 4 | ▶ | return if not looks_like_number($left); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 220 | 4 | ▶ | return if not looks_like_number($right); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 221 | 4 | ▶ | return JSON::true if $left <= $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 222 | 1 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||
| 225 | 10 | ▶ | sub jp_join { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_join: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 226 | 10 | my ( $glue, $array ) = @_; | |||||||||||||||||||||||||||||||||
| 227 | 10 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 228 | ->new({ message => 'Not an array: ' . $array }) | ||||||||||||||||||||||||||||||||||
| 229 | ->throw | ||||||||||||||||||||||||||||||||||
| 230 | if ref $array ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
| 231 | 9 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 232 | ->new({ message => 'Glue not a string: ' . $glue }) | ||||||||||||||||||||||||||||||||||
| 233 | ->throw | ||||||||||||||||||||||||||||||||||
| 234 | if jp_type($glue) ne 'string'; | ||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||
| 236 | 8 | foreach (@$array) { | |||||||||||||||||||||||||||||||||
| 237 | 17 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
jp_type($_) ne "string" and ref $_ ne "Jmespath::String"
MC/DC50%1/2
jp_type($_) ne "string" and ref $_ ne "Jmespath::String"
jp_type($_) ne "string"
ref $_ ne "Jmespath::String"
Truth table66%2/3
A and B
A= jp_type($_) ne "string"B= ref $_ ne "Jmespath::String"
| |||||||||||||||||||||||||||||||||||
| 238 | ->new({message => "Cannot join " . jp_type($_) . " $_"}) | ||||||||||||||||||||||||||||||||||
| 239 | ->throw | ||||||||||||||||||||||||||||||||||
| 240 | if jp_type($_) ne 'string' and ref $_ ne 'Jmespath::String'; | ||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||
| 242 | 6 | return join ( $glue, @$array ); | |||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||
| 246 | 5 | ▶ | sub jp_keys { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_keys: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 247 | 5 | my ( $obj ) = @_; | |||||||||||||||||||||||||||||||||
| 248 | 5 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 249 | ->new({ message => 'array keys(object obj) argument illegal' }) | ||||||||||||||||||||||||||||||||||
| 250 | ->throw | ||||||||||||||||||||||||||||||||||
| 251 | if ref $obj ne 'HASH'; | ||||||||||||||||||||||||||||||||||
| 252 | 2 | my @objkeys = keys %$obj; | |||||||||||||||||||||||||||||||||
| 253 | 2 | return \@objkeys; | |||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||
| 256 | 11 | ▶ | sub jp_length { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_length: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 257 | 11 | my ( $subject ) = @_; | |||||||||||||||||||||||||||||||||
| 258 | 11 | my ( $length ) = 0; | |||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||
| 260 | 11 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&JSON::is_bool($subject) or &looks_like_number($subject)
MC/DC100%2/2
&JSON::is_bool($subject) or &looks_like_number($subject)
&JSON::is_bool($subject)
&looks_like_number($subject)
Truth table100%3/3
A or B
A= &JSON::is_bool($subject)B= &looks_like_number($subject)
| |||||||||||||||||||||||||||||||||||
| 261 | ->new({ message => 'number length(string|array|object subject) argument illegal' }) | ||||||||||||||||||||||||||||||||||
| 262 | ->throw | ||||||||||||||||||||||||||||||||||
| 263 | if JSON::is_bool($subject) or looks_like_number($subject); | ||||||||||||||||||||||||||||||||||
| 264 | 9 | ▶ | return scalar @$subject if ref $subject eq 'ARRAY'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 265 | 8 | ▶ | return scalar keys %$subject if ref $subject eq 'HASH'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 266 | 6 | return length $subject; | |||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||
| 269 | 8 | ▶ | sub jp_map { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_map: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 270 | 8 | my ($expr, $elements) = @_; | |||||||||||||||||||||||||||||||||
| 271 | # return [] if ref $elements ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
| 272 | 8 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 273 | ->new({ message => 'array[any] map(expression->any->any expr, array[any] elements) undefined elements' }) | ||||||||||||||||||||||||||||||||||
| 274 | ->throw | ||||||||||||||||||||||||||||||||||
| 275 | if not defined $elements; | ||||||||||||||||||||||||||||||||||
| 276 | 7 | my $result = []; | |||||||||||||||||||||||||||||||||
| 277 | 7 | foreach my $element (@$elements) { | |||||||||||||||||||||||||||||||||
| 278 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 279 | 29 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 280 | ->new({ message => 'array[any] map(expression->any->any expr, array[any] elements) undefined elements' }) | ||||||||||||||||||||||||||||||||||
| 281 | ->throw | ||||||||||||||||||||||||||||||||||
| 282 | if not defined $element; | ||||||||||||||||||||||||||||||||||
| 283 | 29 | my $res = $expr->visit($expr->{expression}, $element); | |||||||||||||||||||||||||||||||||
| 284 | 29 | push @$result, $res; | |||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||
| 286 | 7 | return $result; | |||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||
| 289 | # must be all numbers or strings in order to work | ||||||||||||||||||||||||||||||||||
| 290 | # perhaps consider List::Util max() | ||||||||||||||||||||||||||||||||||
| 291 | 10 | ▶ | sub jp_max { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_max: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 292 | 10 | my ( $collection ) = @_; | |||||||||||||||||||||||||||||||||
| 293 | 10 | ▶ | Jmespath::ValueException->new({message=>'max(string|number array) argument not an array'})->throw | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 294 | if ref $collection ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
| 295 | 9 | my ($current_type, $current_max); | |||||||||||||||||||||||||||||||||
| 296 | 9 | foreach my $arg (@$collection) { | |||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||
| 298 | 33 | my $type = jp_type($arg); | |||||||||||||||||||||||||||||||||
| 299 | 33 | ▶ | $current_type = $type if not defined $current_type; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 300 | 33 | ▶ | $current_max = $arg if not defined $current_max; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||
| 302 | 33 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 303 | ->new({message=>"max(string|number array) mixed types not allowed"}) | ||||||||||||||||||||||||||||||||||
| 304 | ->throw | ||||||||||||||||||||||||||||||||||
| 305 | if $type ne $current_type; | ||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||
| 307 | 32 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type ne "number" and $type ne "string"
MC/DC0%0/2
$type ne "number" and $type ne "string"
$type ne "number"
$type ne "string"
Truth table66%2/3
A and B
A= $type ne "number"B= $type ne "string"
| |||||||||||||||||||||||||||||||||||
| 308 | ->new({message=>"max(string|number array) $type not allowed"}) | ||||||||||||||||||||||||||||||||||
| 309 | ->throw | ||||||||||||||||||||||||||||||||||
| 310 | if $type ne 'number' and $type ne 'string'; | ||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||
| 312 | 32 | ▶ | if (looks_like_number($arg) and $arg > $current_max) { $current_max = $arg; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&looks_like_number($arg) and $arg > $current_max
MC/DC100%2/2
&looks_like_number($arg) and $arg > $current_max
&looks_like_number($arg)
$arg > $current_max
Truth table100%3/3
A and B
A= &looks_like_number($arg)B= $arg > $current_max
| |||||||||||||||||||||||||||||||||||
| 313 | 32 | ▶ | if (not looks_like_number($arg) and $arg gt $current_max) { $current_max = $arg; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not &looks_like_number($arg) and $arg gt $current_max
MC/DC100%2/2
not &looks_like_number($arg) and $arg gt $current_max
not &looks_like_number($arg)
$arg gt $current_max
Truth table100%3/3
not(A) and B
A= not &looks_like_number($arg)B= $arg gt $current_max
| |||||||||||||||||||||||||||||||||||
| 314 | 32 | $current_type = $type; | |||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||
| 316 | 8 | return $current_max; | |||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||
| 319 | 5 | ▶ | sub jp_max_by { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_max_by: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 320 | 5 | my ($array, $expref) = @_; | |||||||||||||||||||||||||||||||||
| 321 | 5 | my $values = {}; | |||||||||||||||||||||||||||||||||
| 322 | 5 | foreach my $item (@$array) { | |||||||||||||||||||||||||||||||||
| 323 | 19 | my $result = $expref->visit($expref->{expression}, $item); | |||||||||||||||||||||||||||||||||
| 324 | 19 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $result or &JSON::is_bool($result)
MC/DC100%2/2
not defined $result or &JSON::is_bool($result)
not defined $result
&JSON::is_bool($result)
Truth table100%3/3
not(A) or B
A= not defined $resultB= &JSON::is_bool($result)
| |||||||||||||||||||||||||||||||||||
| 325 | ->new({message=>"min(string|number array) mixed types not allowed"}) | ||||||||||||||||||||||||||||||||||
| 326 | ->throw | ||||||||||||||||||||||||||||||||||
| 327 | if not defined $result or JSON::is_bool($result); | ||||||||||||||||||||||||||||||||||
| 328 | 17 | $values->{ $result } = $item; | |||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||
| 330 | 3 | my @keyed_on = keys %$values; | |||||||||||||||||||||||||||||||||
| 331 | 3 | return $values->{ jp_max( \@keyed_on ) }; | |||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | # this needs to be a comparison function based on the "type" that is | ||||||||||||||||||||||||||||||||||
| 335 | # being sorted so the correct min/max will be taken by type. | ||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | sub jp_keyed_max { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_keyed_max: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 338 | 0 | my ($array, $keyfunc) = @_; | |||||||||||||||||||||||||||||||||
| 339 | 0 | return $array; | |||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | sub _create_key_func { | ||||||||||||||||||||||||||||||||
|
Subroutine
_create_key_func: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 343 | 0 | my ($expref, $allowed_types, $function_name) = @_; | |||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | my $keyfunc = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 345 | 0 | my $result = $expref->visit($expref->{expression}, shift); | |||||||||||||||||||||||||||||||||
| 346 | 0 | }; | |||||||||||||||||||||||||||||||||
| 347 | 0 | return $keyfunc; | |||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||
| 350 | 5 | ▶ | sub jp_merge { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_merge: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 351 | 5 | my @objects = @_; | |||||||||||||||||||||||||||||||||
| 352 | 5 | my $merged = {}; | |||||||||||||||||||||||||||||||||
| 353 | 5 | foreach my $object (@objects) { | |||||||||||||||||||||||||||||||||
| 354 | 10 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 355 | ->new({message=>"object merge([object *argument, [, object $...]])"}) | ||||||||||||||||||||||||||||||||||
| 356 | ->throw | ||||||||||||||||||||||||||||||||||
| 357 | if ref $object ne 'HASH'; | ||||||||||||||||||||||||||||||||||
| 358 | 10 | foreach my $key (keys %$object) { | |||||||||||||||||||||||||||||||||
| 359 | 9 | $merged->{$key} = $object->{$key}; | |||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||
| 362 | 5 | return $merged; | |||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||
| 365 | 10 | ▶ | sub jp_min { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_min: called CC=12 SCAR=25.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 366 | 10 | my ($collection) = @_; | |||||||||||||||||||||||||||||||||
| 367 | 10 | ▶ | Jmespath::ValueException->new({message=>'min(string|number array) argument not an array'})->throw | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 368 | if ref $collection ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
| 369 | 9 | my ($current_type, $current_min); | |||||||||||||||||||||||||||||||||
| 370 | 9 | foreach my $arg (@$collection) { | |||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||
| 372 | 33 | my $type = jp_type($arg); | |||||||||||||||||||||||||||||||||
| 373 | 33 | ▶ | $current_type = $type if not defined $current_type; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 374 | 33 | ▶ | $current_min = $arg if not defined $current_min; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||
| 376 | 33 | ▶ | Jmespath::ValueException->new({message=>"min(string|number array) mixed types not allowed"})->throw | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 377 | if $type ne $current_type; | ||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||
| 379 | 32 | ▶ | Jmespath::ValueException->new({message=>"min(string|number array) $type not allowed"})->throw | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type ne "number" and $type ne "string"
MC/DC0%0/2
$type ne "number" and $type ne "string"
$type ne "number"
$type ne "string"
Truth table66%2/3
A and B
A= $type ne "number"B= $type ne "string"
| |||||||||||||||||||||||||||||||||||
| 380 | if $type ne 'number' and $type ne 'string'; | ||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||
| 382 | 32 | ▶ | if (looks_like_number($arg) and $arg < $current_min) { $current_min = $arg; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&looks_like_number($arg) and $arg < $current_min
MC/DC100%2/2
&looks_like_number($arg) and $arg < $current_min
&looks_like_number($arg)
$arg < $current_min
Truth table100%3/3
A and B
A= &looks_like_number($arg)B= $arg < $current_min
| |||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | if (not looks_like_number($arg) and $arg lt $current_min) { $current_min = $arg; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not &looks_like_number($arg) and $arg lt $current_min
MC/DC0%0/2
not &looks_like_number($arg) and $arg lt $current_min
not &looks_like_number($arg)
$arg lt $current_min
Truth table66%2/3
not(A) and B
A= not &looks_like_number($arg)B= $arg lt $current_min
| |||||||||||||||||||||||||||||||||||
| 384 | 32 | $current_type = $type; | |||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||
| 386 | 8 | return $current_min; | |||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||
| 389 | 5 | ▶ | sub jp_min_by { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_min_by: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 390 | 5 | my ($array, $expref) = @_; | |||||||||||||||||||||||||||||||||
| 391 | 5 | my $values = {}; | |||||||||||||||||||||||||||||||||
| 392 | 5 | foreach my $item (@$array) { | |||||||||||||||||||||||||||||||||
| 393 | 19 | my $result = $expref->visit($expref->{expression}, $item); | |||||||||||||||||||||||||||||||||
| 394 | 19 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $result or &JSON::is_bool($result)
MC/DC100%2/2
not defined $result or &JSON::is_bool($result)
not defined $result
&JSON::is_bool($result)
Truth table100%3/3
not(A) or B
A= not defined $resultB= &JSON::is_bool($result)
| |||||||||||||||||||||||||||||||||||
| 395 | ->new({message=>"min(string|number array) mixed types not allowed"}) | ||||||||||||||||||||||||||||||||||
| 396 | ->throw | ||||||||||||||||||||||||||||||||||
| 397 | if not defined $result or JSON::is_bool($result); | ||||||||||||||||||||||||||||||||||
| 398 | 17 | $values->{ $result } = $item; | |||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||
| 400 | 3 | my @keyed_on = keys %$values; | |||||||||||||||||||||||||||||||||
| 401 | 3 | return $values->{ jp_min( \@keyed_on ) }; | |||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||
| 404 | 130 | ▶ | sub jp_ne { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_ne: called CC=23 SCAR=31.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 405 | 130 | my ($left, $right) = @_; | |||||||||||||||||||||||||||||||||
| 406 | 130 | ▶ | return JSON::false if not defined $left and not defined $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $left or defined $right
MC/DC100%2/2
defined $left or defined $right
defined $left
defined $right
Truth table100%3/3
A or B
A= defined $leftB= defined $right
| |||||||||||||||||||||||||||||||||||
| 407 | 128 | ▶ | return JSON::true if not defined $left or not defined $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $left and defined $right
MC/DC100%2/2
defined $left and defined $right
defined $left
defined $right
Truth table100%3/3
A and B
A= defined $leftB= defined $right
| |||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||
| 409 | 100 | ▶ | if (ref($left) eq 'JSON::PP::Boolean' or | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "JSON::PP::Boolean" or ref $right eq "JSON::PP::Boolean"
MC/DC100%2/2
ref $left eq "JSON::PP::Boolean" or ref $right eq "JSON::PP::Boolean"
ref $left eq "JSON::PP::Boolean"
ref $right eq "JSON::PP::Boolean"
Truth table100%3/3
A or B
A= ref $left eq "JSON::PP::Boolean"B= ref $right eq "JSON::PP::Boolean"
| |||||||||||||||||||||||||||||||||||
| 410 | ref($right) eq 'JSON::PP::Boolean') { | ||||||||||||||||||||||||||||||||||
| 411 | 48 | ▶ | if (ref($left) eq 'JSON::PP::Boolean' and | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "JSON::PP::Boolean" and ref $right eq "JSON::PP::Boolean"
MC/DC100%2/2
ref $left eq "JSON::PP::Boolean" and ref $right eq "JSON::PP::Boolean"
ref $left eq "JSON::PP::Boolean"
ref $right eq "JSON::PP::Boolean"
Truth table100%3/3
A and B
A= ref $left eq "JSON::PP::Boolean"B= ref $right eq "JSON::PP::Boolean"
| |||||||||||||||||||||||||||||||||||
| 412 | ref($right) eq 'JSON::PP::Boolean' ) { | ||||||||||||||||||||||||||||||||||
| 413 | 8 | ▶ | return JSON::true if $left != $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 414 | 4 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||
| 416 | # else { | ||||||||||||||||||||||||||||||||||
| 417 | # return JSON::false; | ||||||||||||||||||||||||||||||||||
| 418 | # } | ||||||||||||||||||||||||||||||||||
| 419 | 40 | return JSON::true; | |||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||
| 422 | 52 | ▶ | if (ref($left) eq 'HASH' or ref($right) eq 'HASH') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "HASH" or ref $right eq "HASH"
MC/DC100%2/2
ref $left eq "HASH" or ref $right eq "HASH"
ref $left eq "HASH"
ref $right eq "HASH"
Truth table100%3/3
A or B
A= ref $left eq "HASH"B= ref $right eq "HASH"
| |||||||||||||||||||||||||||||||||||
| 423 | 24 | ▶ | if (ref($left) eq 'HASH' and ref($right) eq 'HASH') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "HASH" and ref $right eq "HASH"
MC/DC100%2/2
ref $left eq "HASH" and ref $right eq "HASH"
ref $left eq "HASH"
ref $right eq "HASH"
Truth table100%3/3
A and B
A= ref $left eq "HASH"B= ref $right eq "HASH"
| |||||||||||||||||||||||||||||||||||
| 424 | 4 | ▶ | return JSON::false if hashes_equal($left, $right); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||
| 426 | 22 | return JSON::true; | |||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||
| 429 | 28 | ▶ | if (ref($left) eq 'ARRAY' or ref($right) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "ARRAY" or ref $right eq "ARRAY"
MC/DC100%2/2
ref $left eq "ARRAY" or ref $right eq "ARRAY"
ref $left eq "ARRAY"
ref $right eq "ARRAY"
Truth table100%3/3
A or B
A= ref $left eq "ARRAY"B= ref $right eq "ARRAY"
| |||||||||||||||||||||||||||||||||||
| 430 | 16 | ▶ | if (ref($left) eq 'ARRAY' and ref($right) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $left eq "ARRAY" and ref $right eq "ARRAY"
MC/DC100%2/2
ref $left eq "ARRAY" and ref $right eq "ARRAY"
ref $left eq "ARRAY"
ref $right eq "ARRAY"
Truth table100%3/3
A and B
A= ref $left eq "ARRAY"B= ref $right eq "ARRAY"
| |||||||||||||||||||||||||||||||||||
| 431 | 4 | ▶ | return JSON::false if arrays_equal($left, $right); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||
| 433 | 14 | return JSON::true; | |||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||
| 437 | 12 | ▶ | if (looks_like_number($left) and | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&looks_like_number($left) and &looks_like_number($right)
MC/DC0%0/2
&looks_like_number($left) and &looks_like_number($right)
&looks_like_number($left)
&looks_like_number($right)
Truth table33%1/3
A and B
A= &looks_like_number($left)B= &looks_like_number($right)
| |||||||||||||||||||||||||||||||||||
| 438 | looks_like_number($right)) { | ||||||||||||||||||||||||||||||||||
| 439 | 12 | ▶ | return JSON::true if $left != $right; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 440 | 5 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||
| 443 | 0 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||
| 446 | # | ||||||||||||||||||||||||||||||||||
| 447 | # | ||||||||||||||||||||||||||||||||||
| 448 | 10 | ▶ | sub jp_not_null { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_not_null: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 449 | 10 | my @arguments = @_; | |||||||||||||||||||||||||||||||||
| 450 | 10 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 451 | ->new({ message => 'not_null() requires at least one argument' }) | ||||||||||||||||||||||||||||||||||
| 452 | ->throw | ||||||||||||||||||||||||||||||||||
| 453 | if not @arguments; | ||||||||||||||||||||||||||||||||||
| 454 | 9 | my $result = []; | |||||||||||||||||||||||||||||||||
| 455 | 9 | foreach my $argument (@arguments) { | |||||||||||||||||||||||||||||||||
| 456 | 26 | ▶ | next if not defined $argument; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 457 | 8 | ▶ | return $argument if defined $argument; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||
| 459 | 1 | return; | |||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||
| 462 | 5 | ▶ | sub jp_reverse { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_reverse: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 463 | 5 | my $arg = shift; | |||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||
| 465 | 5 | ▶ | if (ref $arg eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 466 | 3 | my $result = []; | |||||||||||||||||||||||||||||||||
| 467 | 3 | ▶ | for ( my $idx = scalar @$arg - 1; $idx >= 0; $idx--) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 468 | 10 | push @$result, @$arg[$idx]; | |||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||
| 470 | 3 | return $result; | |||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||
| 472 | elsif (ref $arg eq '') { | ||||||||||||||||||||||||||||||||||
| 473 | 2 | return reverse $arg; | |||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||
| 475 | 0 | return; | |||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||
| 478 | 9 | ▶ | sub jp_sort { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_sort: called CC=9 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 479 | 9 | my $list = shift; | |||||||||||||||||||||||||||||||||
| 480 | 9 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $list or ref $list ne "ARRAY"
MC/DC100%2/2
not defined $list or ref $list ne "ARRAY"
not defined $list
ref $list ne "ARRAY"
Truth table100%3/3
not(A) or B
A= not defined $listB= ref $list ne "ARRAY"
| |||||||||||||||||||||||||||||||||||
| 481 | ->new({ message=>'array sort(array[number]|array[string] $list) illegal argument' }) | ||||||||||||||||||||||||||||||||||
| 482 | ->throw | ||||||||||||||||||||||||||||||||||
| 483 | if not defined $list or ref $list ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
| 484 | 7 | my $current_type; | |||||||||||||||||||||||||||||||||
| 485 | 7 | foreach (@$list) { | |||||||||||||||||||||||||||||||||
| 486 | 19 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 487 | ->new({ message=>'array sort(array[number]|array[string] $list) illegal argument' }) | ||||||||||||||||||||||||||||||||||
| 488 | ->throw | ||||||||||||||||||||||||||||||||||
| 489 | if ref $_ ne ''; | ||||||||||||||||||||||||||||||||||
| 490 | 19 | ▶ | $current_type = jp_type($_) if not defined $current_type; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 491 | 19 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$current_type ne "string" and $current_type ne "number"
MC/DC0%0/2
$current_type ne "string" and $current_type ne "number"
$current_type ne "string"
$current_type ne "number"
Truth table66%2/3
A and B
A= $current_type ne "string"B= $current_type ne "number"
| |||||||||||||||||||||||||||||||||||
| 492 | ->new({ message=>'array sort(array[number]|array[string] $list) illegal argument' }) | ||||||||||||||||||||||||||||||||||
| 493 | ->throw | ||||||||||||||||||||||||||||||||||
| 494 | if $current_type ne 'string' and $current_type ne 'number'; | ||||||||||||||||||||||||||||||||||
| 495 | 19 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 496 | ->new({ message=>'array sort(array[number]|array[string] $list) mixed types' }) | ||||||||||||||||||||||||||||||||||
| 497 | ->throw | ||||||||||||||||||||||||||||||||||
| 498 | if $current_type ne jp_type($_); | ||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||
| 501 | 6 | my @result = sort { $a cmp $b } @$list ; | |||||||||||||||||||||||||||||||||
| 502 | 6 | return \@result; | |||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||
| 505 | 11 | ▶ | sub jp_sort_by { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_sort_by: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 506 | 11 | my ($array, $expref) = @_; | |||||||||||||||||||||||||||||||||
| 507 | 11 | my $values = {}; | |||||||||||||||||||||||||||||||||
| 508 | 11 | my $keyed = []; | |||||||||||||||||||||||||||||||||
| 509 | 11 | my $current_type; | |||||||||||||||||||||||||||||||||
| 510 | # create "symbol map" for items | ||||||||||||||||||||||||||||||||||
| 511 | 11 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 512 | ->new({message=>"sort_by(array elements, expression->number|expression->string expr) undefined expr not allowed"}) | ||||||||||||||||||||||||||||||||||
| 513 | ->throw | ||||||||||||||||||||||||||||||||||
| 514 | if not defined $expref; | ||||||||||||||||||||||||||||||||||
| 515 | 10 | ▶ | for (my $idx = 0; $idx < scalar @$array; $idx++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 516 | 45 | $values->{$idx} = @{$array}[$idx]; | |||||||||||||||||||||||||||||||||
| 517 | 45 | my $evaled = $expref->visit($expref->{expression}, @{$array}[$idx]); | |||||||||||||||||||||||||||||||||
| 518 | 45 | ▶ | $current_type = jp_type($evaled) if not defined $current_type; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||
| 520 | 45 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 521 | ->new({message=>"sort_by(array elements, expression->number|expression->string expr) undefined expr not allowed"}) | ||||||||||||||||||||||||||||||||||
| 522 | ->throw | ||||||||||||||||||||||||||||||||||
| 523 | if jp_type($evaled) ne $current_type; | ||||||||||||||||||||||||||||||||||
| 524 | 43 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $evaled or &JSON::is_bool($evaled)
MC/DC50%1/2
not defined $evaled or &JSON::is_bool($evaled)
not defined $evaled
&JSON::is_bool($evaled)
Truth table66%2/3
not(A) or B
A= not defined $evaledB= &JSON::is_bool($evaled)
| |||||||||||||||||||||||||||||||||||
| 525 | ->new({message=>"min(string|number array) mixed types not allowed"}) | ||||||||||||||||||||||||||||||||||
| 526 | ->throw | ||||||||||||||||||||||||||||||||||
| 527 | if not defined $evaled or JSON::is_bool($evaled); | ||||||||||||||||||||||||||||||||||
| 528 | 42 | push @$keyed, [ $evaled, $idx ]; | |||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||
| 530 | 7 | my @sorted = sort { $a->[0] cmp $b->[0] } @$keyed; | |||||||||||||||||||||||||||||||||
| 531 | 7 | my $res = []; | |||||||||||||||||||||||||||||||||
| 532 | 7 | foreach my $item (@sorted) { | |||||||||||||||||||||||||||||||||
| 533 | 36 | push @$res, $values->{$item->[1]}; | |||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||
| 535 | 7 | return $res; | |||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||
| 538 | 5 | ▶ | sub jp_starts_with { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_starts_with: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 539 | 5 | my ($subject, $prefix) = @_; | |||||||||||||||||||||||||||||||||
| 540 | 5 | ▶ | Jmespath::ValueException->new({message=>'starts_with(subject, prefix) requires two arguments'})->throw | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $subject and defined $prefix
MC/DC0%0/2
defined $subject and defined $prefix
defined $subject
defined $prefix
Truth table33%1/3
A and B
A= defined $subjectB= defined $prefix
| |||||||||||||||||||||||||||||||||||
| 541 | if not defined $subject or not defined $prefix; | ||||||||||||||||||||||||||||||||||
| 542 | 5 | ▶ | Jmespath::ValueException->new({message=>'starts_with(subject, prefix) not a string'})->throw | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 543 | if looks_like_number($prefix); | ||||||||||||||||||||||||||||||||||
| 544 | 4 | ▶ | return JSON::true if $subject =~ /^$prefix/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 545 | 1 | return JSON::false; | |||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||
| 548 | 6 | ▶ | sub jp_sum { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_sum: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 549 | 6 | my $data = shift; | |||||||||||||||||||||||||||||||||
| 550 | 6 | my $result = 0; | |||||||||||||||||||||||||||||||||
| 551 | 6 | foreach my $value (@$data) { | |||||||||||||||||||||||||||||||||
| 552 | 21 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 553 | ->new({message=>'sum(numbers) member not a number'}) | ||||||||||||||||||||||||||||||||||
| 554 | ->throw | ||||||||||||||||||||||||||||||||||
| 555 | if not looks_like_number($value); | ||||||||||||||||||||||||||||||||||
| 556 | 20 | $result += $value; | |||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||
| 558 | 5 | return $result; | |||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||
| 561 | 5 | ▶ | sub jp_to_array { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_to_array: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 562 | 5 | my ($arg) = shift; | |||||||||||||||||||||||||||||||||
| 563 | 5 | ▶ | return [$arg] if JSON::is_bool($arg); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 564 | 4 | ▶ | return [$arg] if ref $arg eq 'HASH'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 565 | 3 | ▶ | return $arg if ref $arg eq 'ARRAY'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 566 | 2 | return [$arg]; | |||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||
| 569 | 10 | ▶ | sub jp_to_string { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_to_string: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 570 | 10 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||
| 571 | 10 | ▶ | $arg = JSON->new->pretty(0)->allow_nonref->encode( $arg ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
jp_type($arg) eq "object" or jp_type($arg) eq "array"
MC/DC50%1/2
jp_type($arg) eq "object" or jp_type($arg) eq "array"
jp_type($arg) eq "object"
jp_type($arg) eq "array"
Truth table66%2/3
A or B
A= jp_type($arg) eq "object"B= jp_type($arg) eq "array"
| |||||||||||||||||||||||||||||||||||
| 572 | if jp_type($arg) eq 'object' | ||||||||||||||||||||||||||||||||||
| 573 | or jp_type($arg) eq 'array'; | ||||||||||||||||||||||||||||||||||
| 574 | 10 | ▶ | $arg = do { bless \( my $dummy = $arg), "Jmespath::String" } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 575 | if jp_type($arg) eq 'number'; | ||||||||||||||||||||||||||||||||||
| 576 | 10 | return $arg; | |||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||
| 579 | 35 | ▶ | sub jp_to_number { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_to_number: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 580 | 35 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||
| 582 | 35 | ▶ | return if not looks_like_number($arg); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 583 | 29 | ▶ | return if JSON::is_bool($arg); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 584 | 28 | $arg += 0; # remove trailing 0's | |||||||||||||||||||||||||||||||||
| 585 | 28 | return $arg; | |||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||
| 588 | 212 | ▶ | sub jp_type { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_type: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 589 | 212 | my ($item) = @_; | |||||||||||||||||||||||||||||||||
| 590 | 212 | ▶ | return 'null' if not defined $item; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 591 | 210 | ▶ | if (JSON::is_bool($item)) { return 'boolean'; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 592 | 206 | ▶ | if (looks_like_number($item)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 593 | 146 | ▶ | return 'string' if ref $item eq 'Jmespath::String'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 594 | 146 | return 'number'; | |||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||
| 596 | 60 | ▶ | if (ref($item) eq 'ARRAY') { return 'array';} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 597 | 57 | ▶ | if (ref($item) eq 'HASH' ) {return 'object';} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 598 | 55 | return 'string'; | |||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||
| 601 | 2 | ▶ | sub jp_values { | ||||||||||||||||||||||||||||||||
|
Subroutine
jp_values: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 602 | 2 | my $obj = shift; | |||||||||||||||||||||||||||||||||
| 603 | 2 | ▶ | Jmespath::ValueException | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 604 | ->new({message =>'array values(object $obj): illegal argument'}) | ||||||||||||||||||||||||||||||||||
| 605 | ->throw | ||||||||||||||||||||||||||||||||||
| 606 | if ref $obj ne 'HASH'; | ||||||||||||||||||||||||||||||||||
| 607 | 1 | my $result = []; | |||||||||||||||||||||||||||||||||
| 608 | 1 | foreach my $item (keys %$obj) { | |||||||||||||||||||||||||||||||||
| 609 | 2 | push @$result, $obj->{$item}; | |||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||
| 611 | 1 | return $result; | |||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||
| 615 | 14 | ▶ | sub arrays_equal { | ||||||||||||||||||||||||||||||||
|
Subroutine
arrays_equal: called CC=13 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 616 | 14 | my ( $a, $b ) = @_; | |||||||||||||||||||||||||||||||||
| 617 | 14 | ▶ | if ( scalar @$a != scalar @$b ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 618 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||
| 620 | 14 | for my $i ( 0 .. $#{$a} ) { | |||||||||||||||||||||||||||||||||
| 621 | 14 | my $va = $a->[$i]; | |||||||||||||||||||||||||||||||||
| 622 | 14 | my $vb = $b->[$i]; | |||||||||||||||||||||||||||||||||
| 623 | 14 | ▶ | if ( ref $va ne ref $vb ) { | ||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||
| 624 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||
| 626 | ▶ | elsif ( ref $va eq '' and ref $vb eq '' and $va ne $vb) { | |||||||||||||||||||||||||||||||||
|
Condition50%3/6
ref $va eq "" and ref $vb eq "" and $va ne $vb
ref $va eq "" and ref $vb eq ""
MC/DC33%1/3
ref $va eq "" and ref $vb eq "" and $va ne $vb
ref $va eq ""
ref $vb eq ""
$va ne $vb
Truth table50%2/4
A and B and C
A= ref $va eq ""B= ref $vb eq ""C= $va ne $vb
| |||||||||||||||||||||||||||||||||||
| 627 | 6 | return 0; | |||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||
| 629 | ▶ | elsif ( ref $va eq 'SCALAR' && $va ne $vb ) { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $va eq "SCALAR" and $va ne $vb
MC/DC0%0/2
ref $va eq "SCALAR" and $va ne $vb
ref $va eq "SCALAR"
$va ne $vb
Truth table33%1/3
A and B
A= ref $va eq "SCALAR"B= $va ne $vb
| |||||||||||||||||||||||||||||||||||
| 630 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||
| 632 | ▶ | elsif ( ref $va eq 'ARRAY' && !arrays_equal( $va, $vb ) ) { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $va eq "ARRAY" and not arrays_equal($va, $vb)
MC/DC0%0/2
ref $va eq "ARRAY" and not arrays_equal($va, $vb)
ref $va eq "ARRAY"
not arrays_equal($va, $vb)
Truth table33%1/3
A and not(B)
A= ref $va eq "ARRAY"B= not arrays_equal($va, $vb)
| |||||||||||||||||||||||||||||||||||
| 633 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||
| 635 | ▶ | elsif ( ref $va eq 'HASH' && !hashes_equal( $va, $vb ) ) { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $va eq "HASH" and not hashes_equal($va, $vb)
MC/DC0%0/2
ref $va eq "HASH" and not hashes_equal($va, $vb)
ref $va eq "HASH"
not hashes_equal($va, $vb)
Truth table33%1/3
A and not(B)
A= ref $va eq "HASH"B= not hashes_equal($va, $vb)
| |||||||||||||||||||||||||||||||||||
| 636 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||
| 639 | 8 | return 1; | |||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||
| 642 | 15 | ▶ | sub hashes_equal { | ||||||||||||||||||||||||||||||||
|
Subroutine
hashes_equal: called CC=14 SCAR=31.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 643 | 15 | my ( $a, $b ) = @_; | |||||||||||||||||||||||||||||||||
| 644 | 15 | ▶ | if ( scalar( keys %$a ) != scalar( keys %$b ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 645 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||
| 647 | 15 | for my $k ( keys %$a ) { | |||||||||||||||||||||||||||||||||
| 648 | 17 | ▶ | if ( exists $b->{$k} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 649 | 11 | my $va = $a->{$k}; | |||||||||||||||||||||||||||||||||
| 650 | 11 | my $vb = $b->{$k}; | |||||||||||||||||||||||||||||||||
| 651 | 11 | ▶ | if ( ref $va ne ref $vb ) { | ||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||
| 652 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||
| 654 | ▶ | elsif ( ref $va eq '' and ref $vb eq '' and $va ne $vb ) { | |||||||||||||||||||||||||||||||||
|
Condition83%5/6
ref $va eq "" and ref $vb eq "" and $va ne $vb
ref $va eq "" and ref $vb eq ""
MC/DC66%2/3
ref $va eq "" and ref $vb eq "" and $va ne $vb
ref $va eq ""
ref $vb eq ""
$va ne $vb
Truth table75%3/4
A and B and C
A= ref $va eq ""B= ref $vb eq ""C= $va ne $vb
| |||||||||||||||||||||||||||||||||||
| 655 | 2 | return 0; | |||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||
| 657 | ▶ | elsif ( ref $va eq 'SCALAR' && $va ne $vb ) { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $va eq "SCALAR" and $va ne $vb
MC/DC0%0/2
ref $va eq "SCALAR" and $va ne $vb
ref $va eq "SCALAR"
$va ne $vb
Truth table33%1/3
A and B
A= ref $va eq "SCALAR"B= $va ne $vb
| |||||||||||||||||||||||||||||||||||
| 658 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||
| 660 | ▶ | elsif ( ref $va eq 'ARRAY' && !arrays_equal( $va, $vb ) ) { | |||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $va eq "ARRAY" and not arrays_equal($va, $vb)
MC/DC0%0/2
ref $va eq "ARRAY" and not arrays_equal($va, $vb)
ref $va eq "ARRAY"
not arrays_equal($va, $vb)
Truth table66%2/3
A and not(B)
A= ref $va eq "ARRAY"B= not arrays_equal($va, $vb)
| |||||||||||||||||||||||||||||||||||
| 661 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||
| 663 | ▶ | elsif ( ref $va eq 'HASH' && !hashes_equal( $va, $vb ) ) { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $va eq "HASH" and not hashes_equal($va, $vb)
MC/DC0%0/2
ref $va eq "HASH" and not hashes_equal($va, $vb)
ref $va eq "HASH"
not hashes_equal($va, $vb)
Truth table33%1/3
A and not(B)
A= ref $va eq "HASH"B= not hashes_equal($va, $vb)
| |||||||||||||||||||||||||||||||||||
| 664 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||
| 667 | else { | ||||||||||||||||||||||||||||||||||
| 668 | 6 | return 0; | |||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||
| 671 | 7 | return 1; | |||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||
| 674 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||
| 676 | __END__ | ||||||||||||||||||||||||||||||||||