| 1 | package Amazon::API::EndpointContext::Compiler; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Scalar::Util qw(reftype blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use List::Util qw(any); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | return bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | sub compile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile: called CC=13 SCAR=26.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | my ( $self, $operations ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | ▶ | croak 'operations must be a hash reference' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $operations or builtin::reftype($operations) ne "HASH"
MC/DC50%1/2
not ref $operations or builtin::reftype($operations) ne "HASH"
not ref $operations
builtin::reftype($operations) ne "HASH"
Truth table66%2/3
not(A) or B
A= not ref $operationsB= builtin::reftype($operations) ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | if !ref $operations | ||||||||||||||||||||||||||||||||||||||||||
| 26 | || reftype($operations) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | my %compiled; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | foreach my $action ( sort keys %{$operations} ) { | |||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | my $operation_context = $operations->{$action}->{operationContextParams}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | next | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | if !$operation_context; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | croak "operationContextParams for $action must be a hash reference" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $operation_context or builtin::reftype($operation_context) ne "HASH"
MC/DC50%1/2
not ref $operation_context or builtin::reftype($operation_context) ne "HASH"
not ref $operation_context
builtin::reftype($operation_context) ne "HASH"
Truth table66%2/3
not(A) or B
A= not ref $operation_contextB= builtin::reftype($operation_context) ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | if !ref $operation_context | ||||||||||||||||||||||||||||||||||||||||||
| 38 | || reftype($operation_context) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | foreach my $name ( sort keys %{$operation_context} ) { | |||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | my $definition = $operation_context->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | ▶ | croak "operationContextParams $name for $action must be a hash reference" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $definition or builtin::reftype($definition) ne "HASH"
MC/DC50%1/2
not ref $definition or builtin::reftype($definition) ne "HASH"
not ref $definition
builtin::reftype($definition) ne "HASH"
Truth table66%2/3
not(A) or B
A= not ref $definitionB= builtin::reftype($definition) ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | if !ref $definition | ||||||||||||||||||||||||||||||||||||||||||
| 45 | || reftype($definition) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | my $path = $definition->{path}; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | croak "operationContextParams $name for $action has no path" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not defined $path or ref $path or $path eq ""
not defined $path or ref $path
MC/DC0%0/3
not defined $path or ref $path or $path eq ""
not defined $path
ref $path
$path eq ""
Truth table50%2/4
not(A) or B or C
A= not defined $pathB= ref $pathC= $path eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | if !defined $path | ||||||||||||||||||||||||||||||||||||||||||
| 51 | || ref $path | ||||||||||||||||||||||||||||||||||||||||||
| 52 | || $path eq q{}; | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $compiled{$action}->{$name} | |||||||||||||||||||||||||||||||||||||||||
| 55 | = $self->_compile_expression( $action, $name, $path ); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return \%compiled; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 8 | ▶ | sub _compile_expression { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compile_expression: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 8 | my ( $self, $action, $name, $expression ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | ▶ | if ( $expression =~ /^keys\(([^.()\[\]\s]+)\)$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | return { $1 => { _function => 'keys', }, }; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 7 | ▶ | if ( $expression =~ /^([^.()\[\]\s]+)\[\*\]\.(.+)$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | my $source = $1; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | my $rest = $2; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | $rest =~ s/\[\]$//; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | my @selectors; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | ▶ | if ( $rest =~ /^\[(.+)\]$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | foreach my $selector ( split /\s*,\s*/, $1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | push @selectors, $self->_compile_path( $action, $name, $selector ); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | push @selectors, $self->_compile_path( $action, $name, $rest ); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | return { $source => \@selectors, }; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 5 | return $self->_compile_path( $action, $name, $expression ); | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 10 | ▶ | sub _compile_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compile_path: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 10 | my ( $self, $action, $name, $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 10 | my @parts = split /[.]/, $path, -1; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | croak "unsupported operation context path for $action $name: $path" | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 10 | ▶ | if any { $_ eq q{} || /[\[\](),\s]/ } @parts; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | my $selector = pop @parts; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | ▶ | while (@parts) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | $selector = { pop(@parts) => $selector, }; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | return $selector; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 31 | ▶ | sub _value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 31 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 31 | ▶ | return $value->get__value | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($value) and $value->can("get__value")
MC/DC0%0/2
builtin::blessed($value) and $value->can("get__value")
builtin::blessed($value)
$value->can("get__value")
Truth table33%1/3
A and B
A= builtin::blessed($value)B= $value->can("get__value")
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | if blessed($value) | ||||||||||||||||||||||||||||||||||||||||||
| 120 | && $value->can('get__value'); | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 31 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 18 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 18 | my ( $self, $expression, $parameters ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | return | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 18 | ▶ | if !defined $parameters; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 18 | $parameters = _value($parameters); | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 18 | my ($key) = keys %{$expression}; | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | return | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 18 | ▶ | if !exists $parameters->{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 13 | my $value = _value( $parameters->{$key} ); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 13 | my $selector = $expression->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 13 | ▶ | if ( !ref $selector ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 8 | return $value->{$selector}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | ▶ | if ( reftype($selector) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | ▶ | if ( $selector->{_function} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | return [ keys %{$value} ] | |||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | ▶ | if $selector->{_function} eq 'keys'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | croak "unsupported endpoint context function: $selector->{_function}"; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | return $self->evaluate( $selector, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | ▶ | if ( reftype($selector) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | my @results; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | foreach my $item ( @{$value} ) { | |||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | foreach my $expansion ( @{$selector} ) { | |||||||||||||||||||||||||||||||||||||||||
| 163 | 10 | my $result = $self->evaluate( $expansion, $item ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 10 | ▶ | push @results, $result | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | if defined $result; | ||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | return \@results; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | croak 'unsupported compiled endpoint context expression'; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||