| 1 | package RPC::ExtDirect::Request; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | no warnings 'uninitialized'; ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use RPC::ExtDirect::Config; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use RPC::ExtDirect::Util::Accessor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use RPC::ExtDirect::Util qw/ clean_error_message /; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | ### PACKAGE GLOBAL VARIABLE ### | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # Turn on for debugging | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # DEPRECATED. Use `debug_request` or `debug` Config options instead. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | our $DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | ### PACKAGE GLOBAL VARIABLE ### | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # Set Exception class name so it could be configured | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # DEPRECATED. Use `exception_class_request` or | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # `exception_class` Config options instead. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | our $EXCEPTION_CLASS; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | ### PUBLIC CLASS METHOD (ACCESSOR) ### | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # Return the list of supported hook types | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 68 | ▶ | sub HOOK_TYPES { qw/ before instead after / } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
HOOK_TYPES: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | ### PUBLIC CLASS METHOD (CONSTRUCTOR) ### | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # Initializes new instance of RPC::ExtDirect::Request | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 71 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 71 | my ($class, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 71 | ▶ | my $api = delete $arg->{api} || RPC::ExtDirect->get_api(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $arg->{'api'} || 'RPC::ExtDirect'->get_api
MC/DC0%0/2
delete $arg->{'api'} || 'RPC::ExtDirect'->get_api
delete $arg->{'api'}
'RPC::ExtDirect'->get_api
Truth table33%1/3
A || B
A= delete $arg->{'api'}B= 'RPC::ExtDirect'->get_api
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 71 | ▶ | my $config = delete $arg->{config} || RPC::ExtDirect::Config->new(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $arg->{'config'} || 'RPC::ExtDirect::Config'->new
MC/DC0%0/2
delete $arg->{'config'} || 'RPC::ExtDirect::Config'->new
delete $arg->{'config'}
'RPC::ExtDirect::Config'->new
Truth table33%1/3
A || B
A= delete $arg->{'config'}B= 'RPC::ExtDirect::Config'->new
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | my $debug = exists $arg->{debug} ? !!(delete $arg->{debug}) | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 71 | ▶ | : $config->debug_request | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # Need blessed object to call private methods | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 71 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 56 | api => $api, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | config => $config, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | debug => $debug, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # Unpack and validate arguments | ||||||||||||||||||||||||||||||||||||||||||
| 62 | my ($action_name, $method_name, $tid, $data, $type, $upload, $meta, $aux) | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 71 | = eval { $self->_unpack_arguments($arg) }; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 71 | ▶ | return $self->_exception({ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | action => $action_name, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | method => $method_name, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | tid => $tid, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | message => $@->[0], | ||||||||||||||||||||||||||||||||||||||||||
| 70 | }) if $@; | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # Look up the Method | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 69 | my $method_ref = $api->get_method_by_name($action_name, $method_name); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 69 | ▶ | return $self->_exception({ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | action => $action_name, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | method => $method_name, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | tid => $tid, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | message => 'ExtDirect action or method not found' | ||||||||||||||||||||||||||||||||||||||||||
| 80 | }) unless $method_ref; | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # Check if arguments passed in $data are of right kind | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 65 | my $exception = $self->check_arguments( | |||||||||||||||||||||||||||||||||||||||||
| 84 | action_name => $action_name, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | method_name => $method_name, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | method_ref => $method_ref, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | tid => $tid, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | data => $data, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | metadata => $meta, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 65 | ▶ | return $exception if defined $exception; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | # Bulk assignment for brevity | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 60 | @$self{ qw/ tid type data metadata upload method_ref run_count aux / } | |||||||||||||||||||||||||||||||||||||||||
| 96 | = ($tid, $type, $data, $meta, $upload, $method_ref, 0, $aux); | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | # Finally, resolve the hooks; it's easier to do that upfront | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # since it involves API lookup | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 60 | for my $hook_type ( $class->HOOK_TYPES ) { | |||||||||||||||||||||||||||||||||||||||||
| 101 | 180 | my $hook = $api->get_hook( | |||||||||||||||||||||||||||||||||||||||||
| 102 | action => $action_name, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | method => $method_name, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | type => $hook_type, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 180 | ▶ | $self->$hook_type($hook) if $hook; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 60 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # Checks if method arguments are in order | ||||||||||||||||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 8 | my @checkers = qw/ check_method_arguments check_method_metadata /; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 8 | my %checker_property = ( | |||||||||||||||||||||||||||||||||||||||||
| 121 | check_method_arguments => 'data', | ||||||||||||||||||||||||||||||||||||||||||
| 122 | check_method_metadata => 'metadata', | ||||||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 56 | ▶ | sub check_arguments { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_arguments: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 56 | my ($self, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 56 | my $action_name = $arg{action_name}; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 56 | my $method_name = $arg{method_name}; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 56 | my $method_ref = $arg{method_ref}; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 56 | my $tid = $arg{tid}; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | # Event poll handlers return Event objects instead of plain data; | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # there is no sense in calling them directly | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 56 | ▶ | if ( $method_ref->pollHandler ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | return $self->_exception({ | |||||||||||||||||||||||||||||||||||||||||
| 137 | action => $action_name, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | method => $method_name, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | tid => $tid, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | message => "ExtDirect pollHandler method ". | ||||||||||||||||||||||||||||||||||||||||||
| 141 | "$action_name.$method_name should not ". | ||||||||||||||||||||||||||||||||||||||||||
| 142 | "be called directly" | ||||||||||||||||||||||||||||||||||||||||||
| 143 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | # One extra check for formHandlers | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 55 | ▶ | if ( $method_ref->formHandler ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 14 | my $data = $arg{data}; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 14 | ▶ | if ( 'HASH' ne ref($data) || !exists $data->{extAction} || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
"HASH" ne ref $data or not exists $data->{"extAction"} or not exists $data->{"extMethod"}
"HASH" ne ref $data or not exists $data->{"extAction"}
MC/DC33%1/3
"HASH" ne ref $data or not exists $data->{"extAction"} or not exists $data->{"extMethod"}
"HASH" ne ref $data
not exists $data->{"extAction"}
not exists $data->{"extMethod"}
Truth table50%2/4
A or not(B) or not(C)
A= "HASH" ne ref $dataB= not exists $data->{"extAction"}C= not exists $data->{"extMethod"}
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | !exists $data->{extMethod} ) | ||||||||||||||||||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | return $self->_exception({ | |||||||||||||||||||||||||||||||||||||||||
| 155 | action => $action_name, | ||||||||||||||||||||||||||||||||||||||||||
| 156 | method => $method_name, | ||||||||||||||||||||||||||||||||||||||||||
| 157 | tid => $tid, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | message => "ExtDirect formHandler method ". | ||||||||||||||||||||||||||||||||||||||||||
| 159 | "$action_name.$method_name should only ". | ||||||||||||||||||||||||||||||||||||||||||
| 160 | "be called with form submits" | ||||||||||||||||||||||||||||||||||||||||||
| 161 | }) | ||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | # The actual heavy lifting happens in the Method itself | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 53 | for my $checker ( @checkers ) { | |||||||||||||||||||||||||||||||||||||||||
| 167 | 105 | my $what = $checker_property{ $checker }; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 105 | my $have = $arg{ $what }; | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 105 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 105 | eval { $method_ref->$checker($have) }; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 105 | ▶ | if ( my $error = $@ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | $error =~ s/\n$//; | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | return $self->_exception({ | |||||||||||||||||||||||||||||||||||||||||
| 178 | action => $action_name, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | method => $method_name, | ||||||||||||||||||||||||||||||||||||||||||
| 180 | tid => $tid, | ||||||||||||||||||||||||||||||||||||||||||
| 181 | message => $error, | ||||||||||||||||||||||||||||||||||||||||||
| 182 | where => ref($method_ref) ."->${checker}", | ||||||||||||||||||||||||||||||||||||||||||
| 183 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | # undef means no exception | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 51 | return undef; ## no critic | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # Runs the request; returns false value if method died on us, | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # true otherwise | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 61 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 61 | my ($self, $env) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | # Ensure run() is not called twice | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 61 | ▶ | return $self->_set_error("ExtDirect request can't run more than once per batch") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | if $self->run_count > 0; | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | # Set the flag | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 60 | $self->run_count(1); | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 60 | my $method_ref = $self->method_ref; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | # Prepare the arguments | ||||||||||||||||||||||||||||||||||||||||||
| 211 | my @method_arg = $method_ref->prepare_method_arguments( | ||||||||||||||||||||||||||||||||||||||||||
| 212 | env => $env, | ||||||||||||||||||||||||||||||||||||||||||
| 213 | input => $self->{data}, | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 60 | upload => $self->upload, | |||||||||||||||||||||||||||||||||||||||||
| 215 | metadata => $self->metadata, | ||||||||||||||||||||||||||||||||||||||||||
| 216 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 60 | my %params = ( | |||||||||||||||||||||||||||||||||||||||||
| 219 | api => $self->api, | ||||||||||||||||||||||||||||||||||||||||||
| 220 | method_ref => $method_ref, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | env => $env, | ||||||||||||||||||||||||||||||||||||||||||
| 222 | arg => \@method_arg, | ||||||||||||||||||||||||||||||||||||||||||
| 223 | metadata => $self->metadata, | ||||||||||||||||||||||||||||||||||||||||||
| 224 | aux_data => $self->aux, | ||||||||||||||||||||||||||||||||||||||||||
| 225 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 60 | my ($run_method, $callee, $result, $exception) = (1); | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | # Run "before" hook if we got one | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 60 | ▶ | ($result, $exception, $run_method) = $self->_run_before_hook(%params) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->before and $self->before->runnable
MC/DC100%2/2
$self->before and $self->before->runnable
$self->before
$self->before->runnable
Truth table100%3/3
A and B
A= $self->beforeB= $self->before->runnable
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | if $self->before && $self->before->runnable; | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | # If there is "instead" hook, call it instead of the method | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 60 | ▶ | ($result, $exception, $callee) = $self->_run_method(%params) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | if $run_method; | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | # Finally, run "after" hook if we got one | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 60 | ▶ | $self->_run_after_hook( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->after and $self->after->runnable
MC/DC50%1/2
$self->after and $self->after->runnable
$self->after
$self->after->runnable
Truth table66%2/3
A and B
A= $self->afterB= $self->after->runnable
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | %params, | ||||||||||||||||||||||||||||||||||||||||||
| 240 | result => $result, | ||||||||||||||||||||||||||||||||||||||||||
| 241 | exception => $exception, | ||||||||||||||||||||||||||||||||||||||||||
| 242 | callee => $callee | ||||||||||||||||||||||||||||||||||||||||||
| 243 | ) if $self->after && $self->after->runnable; | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # Fail gracefully if method call was unsuccessful | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 60 | ▶ | return $self->_process_exception($env, $exception) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | if $exception; | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | # Else stash the results | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 55 | $self->{result} = $result; | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 55 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # | ||||||||||||||||||||||||||||||||||||||||||
| 257 | # If method call was successful, returns result hashref. | ||||||||||||||||||||||||||||||||||||||||||
| 258 | # If an error occured, returns exception hashref. It will contain | ||||||||||||||||||||||||||||||||||||||||||
| 259 | # error-specific message only if we're debugging. This is somewhat weird | ||||||||||||||||||||||||||||||||||||||||||
| 260 | # requirement in ExtDirect specification. If the debug config option | ||||||||||||||||||||||||||||||||||||||||||
| 261 | # is not set, the exception hashref will contain generic error message. | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 47 | ▶ | sub result { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 47 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 47 | return $self->_get_result_hashref(); | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 271 | # | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # Return the data represented as a list | ||||||||||||||||||||||||||||||||||||||||||
| 273 | # | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | sub data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | return 'HASH' eq ref $self->{data} ? %{ $self->{data} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | : 'ARRAY' eq ref $self->{data} ? @{ $self->{data} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | : () | ||||||||||||||||||||||||||||||||||||||||||
| 281 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | ### PUBLIC INSTANCE METHODS ### | ||||||||||||||||||||||||||||||||||||||||||
| 285 | # | ||||||||||||||||||||||||||||||||||||||||||
| 286 | # Simple read-write accessors. | ||||||||||||||||||||||||||||||||||||||||||
| 287 | # | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 8 | my $accessors = [qw/ | |||||||||||||||||||||||||||||||||||||||||
| 290 | config | ||||||||||||||||||||||||||||||||||||||||||
| 291 | api | ||||||||||||||||||||||||||||||||||||||||||
| 292 | debug | ||||||||||||||||||||||||||||||||||||||||||
| 293 | method_ref | ||||||||||||||||||||||||||||||||||||||||||
| 294 | type | ||||||||||||||||||||||||||||||||||||||||||
| 295 | tid | ||||||||||||||||||||||||||||||||||||||||||
| 296 | state | ||||||||||||||||||||||||||||||||||||||||||
| 297 | where | ||||||||||||||||||||||||||||||||||||||||||
| 298 | message | ||||||||||||||||||||||||||||||||||||||||||
| 299 | upload | ||||||||||||||||||||||||||||||||||||||||||
| 300 | run_count | ||||||||||||||||||||||||||||||||||||||||||
| 301 | metadata | ||||||||||||||||||||||||||||||||||||||||||
| 302 | aux | ||||||||||||||||||||||||||||||||||||||||||
| 303 | /, | ||||||||||||||||||||||||||||||||||||||||||
| 304 | __PACKAGE__->HOOK_TYPES, | ||||||||||||||||||||||||||||||||||||||||||
| 305 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 8 | RPC::ExtDirect::Util::Accessor::mk_accessors( | |||||||||||||||||||||||||||||||||||||||||
| 308 | simple => $accessors, | ||||||||||||||||||||||||||||||||||||||||||
| 309 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | ############## PRIVATE METHODS BELOW ############## | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 314 | # | ||||||||||||||||||||||||||||||||||||||||||
| 315 | # Return new Exception object | ||||||||||||||||||||||||||||||||||||||||||
| 316 | # | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 15 | ▶ | sub _exception { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exception: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 15 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 15 | my $config = $self->config; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 15 | my $ex_class = $config->exception_class_request; | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 15 | eval "require $ex_class"; | |||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 15 | my $where = $arg->{where}; | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 15 | ▶ | if ( !$where ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 9 | my ($package, $sub) | |||||||||||||||||||||||||||||||||||||||||
| 330 | = (caller 1)[3] =~ / \A (.*) :: (.*?) \z /xms; | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 9 | $arg->{where} = $package . '->' . $sub; | |||||||||||||||||||||||||||||||||||||||||
| 332 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 15 | return $ex_class->new({ | |||||||||||||||||||||||||||||||||||||||||
| 335 | config => $config, | ||||||||||||||||||||||||||||||||||||||||||
| 336 | debug => $self->debug, | ||||||||||||||||||||||||||||||||||||||||||
| 337 | verbose => $config->verbose_exceptions, | ||||||||||||||||||||||||||||||||||||||||||
| 338 | %$arg | ||||||||||||||||||||||||||||||||||||||||||
| 339 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 343 | # | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # Replaces Request object with Exception object | ||||||||||||||||||||||||||||||||||||||||||
| 345 | # | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 4 | ▶ | sub _set_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_error: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 4 | my ($self, $msg, $where) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | # Munge $where to avoid it being '_set_error' all the time | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 4 | ▶ | if ( !defined $where ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 1 | my ($package, $sub) = (caller 1)[3] =~ / \A (.*) :: (.*?) \z /xms; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | $where = $package . '->' . $sub; | |||||||||||||||||||||||||||||||||||||||||
| 354 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 4 | my $method_ref = $self->method_ref; | |||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | # We need newborn Exception object to tear its guts out | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 4 | my $ex = $self->_exception({ | |||||||||||||||||||||||||||||||||||||||||
| 360 | action => $method_ref->action, | ||||||||||||||||||||||||||||||||||||||||||
| 361 | method => $method_ref->name, | ||||||||||||||||||||||||||||||||||||||||||
| 362 | tid => $self->tid, | ||||||||||||||||||||||||||||||||||||||||||
| 363 | message => $msg, | ||||||||||||||||||||||||||||||||||||||||||
| 364 | where => $where, | ||||||||||||||||||||||||||||||||||||||||||
| 365 | debug => $self->debug, | ||||||||||||||||||||||||||||||||||||||||||
| 366 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | # Now the black voodoo magiKC part, live on stage | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 4 | delete @$self{ keys %$self }; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 4 | @$self{ keys %$ex } = values %$ex; | |||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | # Finally, cover our sins with a blessing and we've been born again! | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 4 | bless $self, ref $ex; | |||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | # Humbly return failure to be propagated upwards | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 4 | return !1; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 380 | # | ||||||||||||||||||||||||||||||||||||||||||
| 381 | # Unpacks arguments into a list and validates them | ||||||||||||||||||||||||||||||||||||||||||
| 382 | # | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 8 | my @std_keys = qw/ | |||||||||||||||||||||||||||||||||||||||||
| 385 | extAction action extMethod method extTID tid data metadata | ||||||||||||||||||||||||||||||||||||||||||
| 386 | extType type extUpload _uploads | ||||||||||||||||||||||||||||||||||||||||||
| 387 | /; | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 71 | ▶ | sub _unpack_arguments { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unpack_arguments: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 71 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | # Unpack and normalize arguments | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 71 | ▶ | my $action = $arg->{extAction} || $arg->{action}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$arg->{'extAction'} || $arg->{'action'}
MC/DC100%2/2
$arg->{'extAction'} || $arg->{'action'}
$arg->{'extAction'}
$arg->{'action'}
Truth table100%3/3
A || B
A= $arg->{'extAction'}B= $arg->{'action'}
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 71 | ▶ | my $method = $arg->{extMethod} || $arg->{method}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$arg->{'extMethod'} || $arg->{'method'}
MC/DC100%2/2
$arg->{'extMethod'} || $arg->{'method'}
$arg->{'extMethod'}
$arg->{'method'}
Truth table100%3/3
A || B
A= $arg->{'extMethod'}B= $arg->{'method'}
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 71 | ▶ | my $tid = $arg->{extTID} || $arg->{tid}; # can't be 0 | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$arg->{'extTID'} || $arg->{'tid'}
MC/DC100%2/2
$arg->{'extTID'} || $arg->{'tid'}
$arg->{'extTID'}
$arg->{'tid'}
Truth table100%3/3
A || B
A= $arg->{'extTID'}B= $arg->{'tid'}
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 71 | ▶ | my $type = $arg->{type} || 'rpc'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$arg->{'type'} || 'rpc'
MC/DC100%1/1
$arg->{'type'} || 'rpc'
$arg->{'type'}
Truth table100%2/2
A
A= $arg->{'type'}
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | # For a formHandler, the "data" field is the form itself; | ||||||||||||||||||||||||||||||||||||||||||
| 399 | # the arguments are fields in the form-encoded POST body | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 71 | ▶ | my $data = $arg->{data} || $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$arg->{'data'} || $arg
MC/DC0%0/2
$arg->{'data'} || $arg
$arg->{'data'}
$arg
Truth table66%2/3
A || B
A= $arg->{'data'}B= $arg
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 71 | my $meta = $arg->{metadata}; | |||||||||||||||||||||||||||||||||||||||||
| 402 | my $upload = $arg->{extUpload} eq 'true' ? $arg->{_uploads} | ||||||||||||||||||||||||||||||||||||||||||
| 403 | : undef | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 71 | ▶ | ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | # Throwing arrayref so that die() wouldn't add file/line to the string | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 71 | ▶ | die [ "ExtDirect action (class name) required" ] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $action and length $action > 0
MC/DC50%1/2
defined $action and length $action > 0
defined $action
length $action > 0
Truth table66%2/3
A and B
A= defined $actionB= length $action > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | unless defined $action && length $action > 0; | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 70 | ▶ | die [ "ExtDirect method name required" ] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $method and length $method > 0
MC/DC50%1/2
defined $method and length $method > 0
defined $method
length $method > 0
Truth table66%2/3
A and B
A= defined $methodB= length $method > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | unless defined $method && length $method > 0; | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 69 | my %arg_keys = map { $_ => 1, } keys %$arg; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 69 | delete @arg_keys{ @std_keys }; | |||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | # Collect ancillary data that might be passed in the packet | ||||||||||||||||||||||||||||||||||||||||||
| 417 | # and make it available to the Hooks. This might be used e.g. | ||||||||||||||||||||||||||||||||||||||||||
| 418 | # for passing CSRF protection tokens, etc. | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 69 | my %aux = map { $_ => $arg->{$_} } keys %arg_keys; | |||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 69 | ▶ | my $aux_ref = %aux ? { %aux } : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 69 | $action, $method, $tid, $data, $type, $upload, $meta, $aux_ref | |||||||||||||||||||||||||||||||||||||||||
| 425 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 429 | # | ||||||||||||||||||||||||||||||||||||||||||
| 430 | # Run "before" hook | ||||||||||||||||||||||||||||||||||||||||||
| 431 | # | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 26 | ▶ | sub _run_before_hook { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_before_hook: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 26 | my ($self, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 26 | my ($run_method, $result, $exception) = (1); | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | # This hook may die() with an Exception | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 26 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 26 | my $hook_result = eval { $self->before->run(%arg) }; | |||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | # If "before" hook died, cancel Method call | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 26 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 3 | $exception = $@; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 3 | $run_method = !1; | |||||||||||||||||||||||||||||||||||||||||
| 446 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | # If "before" hook returns anything but number 1, | ||||||||||||||||||||||||||||||||||||||||||
| 449 | # treat it as an Ext.Direct response and do not call | ||||||||||||||||||||||||||||||||||||||||||
| 450 | # the actual method | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 26 | ▶ | if ( $hook_result ne '1' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 5 | $result = $hook_result; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 5 | $run_method = !1; | |||||||||||||||||||||||||||||||||||||||||
| 454 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 26 | return ($result, $exception, $run_method); | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 460 | # | ||||||||||||||||||||||||||||||||||||||||||
| 461 | # Runs "instead" hook if it exists, or the method itself | ||||||||||||||||||||||||||||||||||||||||||
| 462 | # | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 55 | ▶ | sub _run_method { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_method: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 55 | my ($self, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | # We call methods by code reference | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 55 | my $hook = $self->instead; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 55 | ▶ | my $run_hook = $hook && $hook->runnable; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$hook && $hook->runnable
MC/DC50%1/2
$hook && $hook->runnable
$hook
$hook->runnable
Truth table66%2/3
A && B
A= $hookB= $hook->runnable
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 55 | ▶ | my $callee = $run_hook ? $hook : $self->method_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 55 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 55 | my $result = eval { $callee->run(%arg) }; | |||||||||||||||||||||||||||||||||||||||||
| 474 | 55 | my $exception = $@; | |||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 55 | return ($result, $exception, $callee->code); | |||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 480 | # | ||||||||||||||||||||||||||||||||||||||||||
| 481 | # Run "after" hook | ||||||||||||||||||||||||||||||||||||||||||
| 482 | # | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 24 | ▶ | sub _run_after_hook { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_after_hook: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 24 | my ($self, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | # Localize so that we don't clobber the $@ | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 24 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | # Return value and exceptions are ignored | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 24 | eval { $self->after->run(%arg) }; | |||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 495 | # | ||||||||||||||||||||||||||||||||||||||||||
| 496 | # Return result hashref | ||||||||||||||||||||||||||||||||||||||||||
| 497 | # | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 47 | ▶ | sub _get_result_hashref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_result_hashref: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 47 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 47 | my $method_ref = $self->method_ref; | |||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | my $result_ref = { | ||||||||||||||||||||||||||||||||||||||||||
| 505 | type => 'rpc', | ||||||||||||||||||||||||||||||||||||||||||
| 506 | tid => $self->tid, | ||||||||||||||||||||||||||||||||||||||||||
| 507 | action => $method_ref->action, | ||||||||||||||||||||||||||||||||||||||||||
| 508 | method => $method_ref->name, | ||||||||||||||||||||||||||||||||||||||||||
| 509 | result => $self->{result}, # To avoid collisions | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 47 | }; | |||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 47 | return $result_ref; | |||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||
| 516 | # | ||||||||||||||||||||||||||||||||||||||||||
| 517 | # Process exception message returned by die() in method or hooks | ||||||||||||||||||||||||||||||||||||||||||
| 518 | # | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 5 | ▶ | sub _process_exception { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_exception: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 5 | my ($self, $env, $exception) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | # Stringify exception and treat it as error message | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 5 | my $msg = clean_error_message("$exception"); | |||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | # Report actual package and method in case we're debugging | ||||||||||||||||||||||||||||||||||||||||||
| 527 | 5 | my $method_ref = $self->method_ref; | |||||||||||||||||||||||||||||||||||||||||
| 528 | 5 | my $where = $method_ref->package .'->'. $method_ref->name; | |||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 5 | return $self->_set_error($msg, $where); | |||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||