ExtDirect/API.pm

filter: Statementstmt 95.9% 191 / 199 Branchbran 77.6% 59 / 76 Conditioncond 59.4% 22 / 37 MC/DCmcdc 30.4% 7 / 23 Subroutinesub 100% 25 / 25 Podpod 100% 14 / 14 totaltotal 85.0% 318 / 374 CC 62 SCAR 18.8
CC
62
Cov
87%
get_remoting_api
12.6
add_hook
10.2
init_from_hashref
10.0
CRAP 6.6
« ExtDirect/Request.pm ↑ Summary ExtDirect/Test/Util.pm »
1 package RPC::ExtDirect::API;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶no warnings 'uninitialized'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 27 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 27 ▶use RPC::ExtDirect::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 27 ▶use RPC::ExtDirect::Serializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 27 ▶use RPC::ExtDirect::Util::Accessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 ### PACKAGE GLOBAL VARIABLE ###
14 #
15 # Turn this on for debugging
16 #
17 # DEPRECATED. Use `debug_api` or `debug` Config options instead.
18 #
19  
20 27 our $DEBUG;
21  
22 ### PUBLIC PACKAGE SUBROUTINE ###
23 #
24 # Does not import anything to caller namespace but accepts
25 # configuration parameters. This method always operates on
26 # the "default" API object stored in RPC::ExtDirect
27 #
28  
29 38 ▶sub import {
Subroutine import: called CC=6 SCAR=17.9
30 38 my ($class, @args) = @_;
31  
32 # Nothing to do
33 38 ▶ return unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 30 8 38
34  
35 # Only hash-like arguments are supported
36 8 ▶ croak 'Odd number of arguments in RPC::ExtDirect::API::import()'
Branch: 1 branch
BranchTrueFalseTotal
unless @args % 2 == 0 0 8 8
37 unless (@args % 2) == 0;
38  
39 8 my %arg = @args;
40 8 %arg = map { lc $_ => delete $arg{ $_ } } keys %arg;
41
42 # In most cases that's a formality since RPC::ExtDirect
43 # should be already required elsewhere; some test scripts
44 # may not load it on purpose so we guard against that
45 # just in case. We don't want to `use` RPC::ExtDirect above,
46 # because that would create a circular dependency.
47 8 require RPC::ExtDirect;
48  
49 8 my $api = RPC::ExtDirect->get_api;
50
51 8 for my $type ( $class->HOOK_TYPES ) {
52 24 my $code = delete $arg{ $type };
53
54 24 ▶ $api->add_hook( type => $type, code => $code )
Branch: 1 branch
BranchTrueFalseTotal
if $code 10 14 24
55 if $code;
56 };
57
58 8 my $api_config = $api->config;
59
60 8 for my $option ( keys %arg ) {
61 18 my $value = $arg{$option};
62
63 18 $api_config->$option($value);
64 }
65 }
66  
67 ### PUBLIC CLASS METHOD (ACCESSOR) ###
68 #
69 # Return the hook types supported by the API
70 #
71  
72 83 ▶sub HOOK_TYPES { qw/ before instead after/ }
Subroutine HOOK_TYPES: called CC=1 SCAR=0.0
Pod documented
73  
74 ### PUBLIC CLASS METHOD (CONSTRUCTOR) ###
75 #
76 # Init a new API object
77 #
78  
79 26 ▶sub new {
Subroutine new: called CC=4 SCAR=15.9
Pod documented
80 26 my $class = shift;
81
82 0 ▶ my %arg = @_ == 1 && 'HASH' eq ref($_[0]) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && 'HASH' eq ref $_[0] ? : 0 26 26
Condition33%1/3
@_ == 1 and "HASH" eq ref $_[0]
!ll&&!rl&&r
2600
MC/DC0%0/2
@_ == 1 and "HASH" eq ref $_[0]
@_ == 1 "HASH" eq ref $_[0]
Truth table33%1/3
A and B
A= @_ == 1B= "HASH" eq ref $_[0]
ABresult
0X0
100
111
83
84 26 ▶ $arg{config} ||= RPC::ExtDirect::Config->new();
Condition66%2/3
$arg{"config"} ||= "RPC::ExtDirect::Config"->new
l!l&&r!l&&!r
3230
MC/DC0%0/2
$arg{"config"} ||= "RPC::ExtDirect::Config"->new
$arg{"config"} "RPC::ExtDirect::Config"->new
Truth table66%2/3
A ||= B
A= $arg{"config"}B= "RPC::ExtDirect::Config"->new
ABresult
1X1
011
000
85
86 26 return bless {
87 %arg,
88 actions => {},
89 }, $class;
90 }
91  
92 ### PUBLIC CLASS METHOD (CONSTRUCTOR) ###
93 #
94 # Init a new API object and populate it from the supplied hashref
95 #
96  
97 4 ▶sub new_from_hashref {
Subroutine new_from_hashref: called CC=1 SCAR=0.0
Pod documented
98 4 my ($class, %arg) = @_;
99
100 4 my $api_href = delete $arg{api_href};
101
102 4 my $self = $class->new(%arg);
103
104 4 $self->init_from_hashref($api_href);
105
106 4 return $self;
107 }
108  
109 ### PUBLIC INSTANCE METHOD ###
110 #
111 # Initialize the API from a hashref
112 #
113  
114 4 ▶sub init_from_hashref {
Subroutine init_from_hashref: called CC=10 SCAR=23.1
Pod documented
115 4 my ($self, $api_href) = @_;
116
117 # Global hooks go first
118 4 for my $type ( $self->HOOK_TYPES ) {
119 $self->add_hook( type => $type, code => delete $api_href->{$type} )
120 12 ▶ if exists $api_href->{$type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $api_href->{$type} 2 10 12
121 }
122
123 4 for my $key ( keys %$api_href ) {
124 14 my $action_def = $api_href->{ $key };
125 14 my $remote = $action_def->{remote};
126 14 ▶ my $package = $remote ? undef : $key;
Branch: 1 branch
BranchTrueFalseTotal
$remote ? : 8 6 14
127 14 ▶ my $action_name = $remote ? $key : $action_def->{action};
Branch: 1 branch
BranchTrueFalseTotal
$remote ? : 8 6 14
128
129 14 my $action = $self->add_action(
130 action => $action_name,
131 package => $package,
132 no_overwrite => 1,
133 );
134
135 14 ▶ for my $hook_type ( $remote ? () : $self->HOOK_TYPES ) {
Branch: 1 branch
BranchTrueFalseTotal
$remote ? : 8 6 14
136 18 my $hook_code = $action_def->{$hook_type};
137
138 18 ▶ if ( $hook_code ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hook_code) 0 18 18
139 0 $self->add_hook(
140 package => $package,
141 type => $hook_type,
142 code => $hook_code,
143 );
144 }
145 }
146
147 14 my $methods = $action_def->{methods};
148
149 14 for my $method_name ( keys %$methods ) {
150 56 my $method_def = $methods->{ $method_name };
151
152 56 $self->add_method(
153 action => $action_name,
154 package => $package,
155 method => $method_name,
156 %$method_def
157 );
158 }
159 }
160 }
161  
162 ### PUBLIC INSTANCE METHOD ###
163 #
164 # Returns the JavaScript chunk for REMOTING_API
165 #
166  
167 8 ▶sub get_remoting_api {
Subroutine get_remoting_api: called CC=12 SCAR=25.4
Pod documented
168 8 my ($class, %arg) = @_;
169
170 8 my ($self, $config);
171
172 # There is an option to pass config externally; mainly for testing
173 8 $config = $arg{config};
174
175 # Environment object is optional
176 8 my $env = $arg{env};
177
178 # Backwards compatibility: if called as a class method, operate on
179 # the "global" API object instead, and create a new Config instance
180 # as well to take care of possibly-modified-since global variables
181 8 ▶ if ( ref $class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) { } 5 3 8
182 5 $self = $class;
183 5 ▶ $config ||= $self->config;
Condition33%1/3
$config ||= $self->config
l!l&&r!l&&!r
050
MC/DC0%0/2
$config ||= $self->config
$config $self->config
Truth table33%1/3
A ||= B
A= $configB= $self->config
ABresult
1X1
011
000
184 }
185 else {
186 3 require RPC::ExtDirect;
187  
188 3 $self = RPC::ExtDirect->get_api();
189 3 ▶ $config ||= $self->config->clone();
Condition66%2/3
$config ||= $self->config->clone
l!l&&r!l&&!r
210
MC/DC0%0/2
$config ||= $self->config->clone
$config $self->config->clone
Truth table66%2/3
A ||= B
A= $configB= $self->config->clone
ABresult
1X1
011
000
190
191 3 $config->read_global_vars();
192 }
193
194 # Get REMOTING_API hashref
195 8 my $remoting_api = $self->_get_remoting_api($config, $env);
196  
197 # Get POLLING_API hashref
198 8 my $polling_api = $self->_get_polling_api($config, $env);
199  
200 # Return empty string if we got nothing to declare
201 8 ▶ return '' if !$remoting_api && !$polling_api;
Branch: 1 branch
BranchTrueFalseTotal
unless $remoting_api or $polling_api 0 8 8
Condition33%1/3
$remoting_api or $polling_api
l!l&&r!l&&!r
800
MC/DC0%0/2
$remoting_api or $polling_api
$remoting_api $polling_api
Truth table33%1/3
A or B
A= $remoting_apiB= $polling_api
ABresult
1X1
011
000
202  
203 # Shortcuts
204 8 my $remoting_var = $config->remoting_var;
205 8 my $polling_var = $config->polling_var;
206 8 my $auto_connect = $config->auto_connect;
207 8 my $no_polling = $config->no_polling;
208 8 my $s_class = $config->serializer_class_api;
209 8 my $debug_api = $config->debug_api;
210
211 8 my $serializer = $s_class->new( config => $config );
212
213 8 my $api_json = $serializer->serialize(
214 mute_exceptions => 1,
215 debug => $debug_api,
216 data => [$remoting_api],
217 );
218  
219 # Compile JavaScript for REMOTING_API
220 8 ▶ my $js_chunk = "$remoting_var = " . ($api_json || '{}') . ";\n";
Condition50%1/2
$api_json || '{}'
l!l
80
MC/DC0%0/1
$api_json || '{}'
$api_json
Truth table50%1/2
A
A= $api_json
Aresult
11
00
221  
222 # If auto_connect is on, add client side initialization code
223 8 ▶ $js_chunk .= "Ext.direct.Manager.addProvider($remoting_var);\n"
Branch: 1 branch
BranchTrueFalseTotal
if $auto_connect 4 4 8
224 if $auto_connect;
225  
226 # POLLING_API is added only when there's something in it
227 8 ▶ if ( $polling_api && !$no_polling ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($polling_api and not $no_polling) 5 3 8
Condition66%2/3
$polling_api and not $no_polling
!ll&&!rl&&r
305
MC/DC50%1/2
$polling_api and not $no_polling
$polling_api not $no_polling
Truth table66%2/3
A and not(B)
A= $polling_apiB= not $no_polling
ABresult
0X0
100
111
228 5 $api_json = $serializer->serialize(
229 mute_exceptions => 1,
230 debug => $debug_api,
231 data => [$polling_api],
232 );
233
234 5 ▶ $js_chunk .= "$polling_var = " . ($api_json || '{}' ) . ";\n";
Condition50%1/2
$api_json || '{}'
l!l
50
MC/DC0%0/1
$api_json || '{}'
$api_json
Truth table50%1/2
A
A= $api_json
Aresult
11
00
235  
236 # Same initialization code for POLLING_API if auto connect is on
237 5 ▶ $js_chunk .= "Ext.direct.Manager.addProvider($polling_var);\n"
Branch: 1 branch
BranchTrueFalseTotal
if $auto_connect 3 2 5
238 if $auto_connect;
239 };
240  
241 8 return $js_chunk;
242 }
243  
244 ### PUBLIC INSTANCE METHOD ###
245 #
246 # Get the list of all defined Actions' names
247 #
248  
249 3 ▶sub actions { keys %{ $_[0]->{actions} } }
Subroutine actions: called CC=1 SCAR=0.0
Pod documented
250  
251 ### PUBLIC INSTANCE METHOD ###
252 #
253 # Add an Action (class), or update if it exists
254 #
255  
256 85 ▶sub add_action {
Subroutine add_action: called CC=4 SCAR=13.9
Pod documented
257 85 my ($self, %arg) = @_;
258
259 $arg{action} = $self->_get_action_name( $arg{package} )
260 85 ▶ unless defined $arg{action};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg{"action"} 27 58 85
261
262 85 my $action_name = $arg{action};
263
264 return $self->{actions}->{ $action_name }
265 85 ▶ if $arg{no_overwrite} && exists $self->{actions}->{ $action_name };
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"no_overwrite"} and exists $self->{"actions"}{$action_name} 1 84 85
Condition100%3/3
$arg{"no_overwrite"} and exists $self->{"actions"}{$action_name}
!ll&&!rl&&r
33511
MC/DC100%2/2
$arg{"no_overwrite"} and exists $self->{"actions"}{$action_name}
$arg{"no_overwrite"} exists $self->{"actions"}{$action_name}
Truth table100%3/3
A and B
A= $arg{"no_overwrite"}B= exists $self->{"actions"}{$action_name}
ABresult
0X0
100
111
266
267 84 my $config = $self->config;
268 84 my $a_class = $config->api_action_class();
269
270 # This is to avoid hard binding on the Action class
271 84 eval "require $a_class";
272
273 84 my $action_obj = $a_class->new(
274 config => $config,
275 %arg,
276 );
277
278 84 $self->{actions}->{ $action_name } = $action_obj;
279
280 84 return $action_obj;
281 }
282  
283 ### PUBLIC INSTANCE METHOD ###
284 #
285 # Return Action object by its name
286 #
287  
288 539 ▶sub get_action_by_name {
Subroutine get_action_by_name: called CC=1 SCAR=0.0
Pod documented
289 539 my ($self, $action_name) = @_;
290
291 539 return $self->{actions}->{ $action_name };
292 }
293  
294 ### PUBLIC INSTANCE METHOD ###
295 #
296 # Return Action object by package name
297 #
298  
299 396 ▶sub get_action_by_package {
Subroutine get_action_by_package: called CC=3 SCAR=11.0
Pod documented
300 396 my ($self, $package) = @_;
301
302 396 for my $action ( values %{ $self->{actions} } ) {
303 692 ▶ return $action if $action->package eq $package;
Branch: 1 branch
BranchTrueFalseTotal
if $action->package eq $package 363 329 692
304 }
305
306 33 return;
307 }
308  
309 ### PUBLIC INSTANCE METHOD ###
310 #
311 # Add a Method, or update if it exists.
312 # Also create the Method's Action if it doesn't exist yet
313 #
314  
315 364 ▶sub add_method {
Subroutine add_method: called CC=6 SCAR=18.4
Pod documented
316 364 my ($self, %arg) = @_;
317
318 364 my $package = delete $arg{package};
319 364 my $action_name = delete $arg{action};
320 364 my $method_name = $arg{method};
321
322 # Try to find the Action by the package name
323 364 ▶ my $action = $action_name ? $self->get_action_by_name($action_name)
Branch: 1 branch
BranchTrueFalseTotal
$action_name ? : 30 334 364
324 : $self->get_action_by_package($package)
325 ;
326
327 # If Action is not found, create a new one
328 364 ▶ if ( !$action ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action) 33 331 364
329 33 ▶ $action_name = $self->_get_action_name($package)
Branch: 1 branch
BranchTrueFalseTotal
unless $action_name 33 0 33
330 unless $action_name;
331
332 33 $action = $self->add_action(
333 action => $action_name,
334 package => $package,
335 );
336 }
337
338 # Usually redefining a Method means a typo or something
339 364 ▶ croak "Attempting to redefine Method '$method_name' ".
Branch: 2 branches
BranchTrueFalseTotal
if $action->can($method_name) 0 364 364
$package ? : 0 0 0
340 ($package ? "in package $package" : "in Action '$action_name'")
341 if $action->can($method_name);
342
343 364 $action->add_method(\%arg);
344 }
345  
346 ### PUBLIC INSTANCE METHOD ###
347 #
348 # Return the Method object by Action and Method name
349 #
350  
351 93 ▶sub get_method_by_name {
Subroutine get_method_by_name: called CC=2 SCAR=6.9
Pod documented
352 93 my ($self, $action_name, $method_name) = @_;
353
354 93 my $action = $self->get_action_by_name($action_name);
355
356 93 ▶ return unless $action;
Branch: 1 branch
BranchTrueFalseTotal
unless $action 3 90 93
357
358 90 return $action->method($method_name);
359 }
360  
361 ### PUBLIC INSTANCE METHOD ###
362 #
363 # Add a hook instance
364 #
365  
366 52 ▶sub add_hook {
Subroutine add_hook: called CC=8 SCAR=23.2
Pod documented
367 52 my ($self, %arg) = @_;
368
369 52 my $package = $arg{package};
370 52 my $action_name = $arg{action};
371 52 my $method_name = $arg{method};
372 52 my $type = $arg{type};
373 52 my $code = $arg{code};
374
375 52 my $hook_class = $self->config->api_hook_class;
376
377 # This is to avoid hard binding on RPC::ExtDirect::API::Hook
378 52 { local $@; eval "require $hook_class"; }
379
380 52 my $hook = $hook_class->new( type => $type, code => $code );
381
382 52 ▶ if ( $package || $action_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package or $action_name) { } 40 12 52
Condition66%2/3
$package or $action_name
l!l&&r!l&&!r
40012
MC/DC50%1/2
$package or $action_name
$package $action_name
Truth table66%2/3
A or B
A= $packageB= $action_name
ABresult
1X1
011
000
383 40 my $action;
384
385 40 ▶ if ( $package ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package) { } 40 0 40
386 40 $action = $self->get_action_by_package($package);
387
388 40 ▶ croak "Can't find the Action for package '$package'"
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 40 40
389 unless $action;
390 }
391 else {
392 0 $action = $self->get_action_by_name($action_name);
393
394 0 ▶ croak "Can't find the '$action_name' Action"
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 0 0
395 unless $action;
396 }
397
398 40 ▶ if ( $method_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method_name) { } 0 40 40
399 0 my $method = $action->method($method_name);
400
401 0 ▶ croak "Can't find Method '$method_name'"
Branch: 1 branch
BranchTrueFalseTotal
unless $method 0 0 0
402 unless $method;
403
404 0 $method->$type($hook);
405 }
406 else {
407 40 $action->$type($hook);
408 }
409 }
410 else {
411 12 $self->$type($hook);
412 }
413
414 52 return $hook;
415 }
416  
417 ### PUBLIC INSTANCE METHOD ###
418 #
419 # Return the hook object by Method name, Action or package, and type
420 #
421  
422 411 ▶sub get_hook {
Subroutine get_hook: called CC=6 SCAR=18.4
Pod documented
423 411 my ($self, %arg) = @_;
424
425 my ($action_name, $package, $method_name, $type)
426 411 = @arg{qw/ action package method type/};
427
428 411 ▶ my $action = $action_name ? $self->get_action_by_name($action_name)
Branch: 1 branch
BranchTrueFalseTotal
$action_name ? : 389 22 411
429 : $self->get_action_by_package($package)
430 ;
431
432 411 ▶ croak "Can't find action '", ($action_name || $package),
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 411 411
Condition0%0/3
$action_name || $package
l!l&&r!l&&!r
000
MC/DC0%0/2
$action_name || $package
$action_name $package
Truth table0%0/3
A || B
A= $action_nameB= $package
ABresult
1X1
011
000
433 "' for Method $method_name"
434 unless $action;
435
436 411 my $method = $action->method($method_name);
437
438 411 ▶ my $hook = $method->$type || $action->$type || $self->$type;
Condition100%6/6
$method->$type || $action->$type || $self->$type
l!l&&r!l&&!r
14580186
$method->$type or $action->$type
l!l&&r!l&&!r
27118266
MC/DC100%3/3
$method->$type || $action->$type || $self->$type
$method->$type $action->$type $self->$type
Truth table100%4/4
A or B || C
A= $method->$typeB= $action->$typeC= $self->$type
ABCresult
1XX1
01X1
0011
0000
439
440 411 return $hook;
441 }
442  
443 ### PUBLIC INSTANCE METHOD ###
444 #
445 # Return the list of all installed poll handlers
446 #
447  
448 9 ▶sub get_poll_handlers {
Subroutine get_poll_handlers: called CC=2 SCAR=6.9
Pod documented
449 9 my ($self) = @_;
450
451 9 my @handlers;
452
453 ACTION:
454 9 for my $action ( values %{ $self->{actions} } ) {
455 17 my @methods = map { $action->method($_) }
456 $action->polling_methods();
457
458 17 push @handlers, @methods;
459 }
460
461 9 return @handlers;
462 }
463  
464 ### PUBLIC INSTANCE METHODS ###
465 #
466 # Simple read-write accessors
467 #
468  
469 27 my $accessors = [qw/
470 config
471 /,
472 __PACKAGE__->HOOK_TYPES,
473 ];
474  
475 27 RPC::ExtDirect::Util::Accessor::mk_accessors(
476 simple => $accessors,
477 );
478  
479 ############## PRIVATE METHODS BELOW ##############
480  
481 ### PRIVATE CLASS METHOD ###
482 #
483 # Prepare REMOTING_API hashref
484 #
485  
486 8 ▶sub _get_remoting_api {
Subroutine _get_remoting_api: called CC=6 SCAR=17.9
487 8 my ($self, $config, $env) = @_;
488  
489 8 my %api;
490
491 8 my %actions = %{ $self->{actions} };
492
493 ACTION:
494 8 foreach my $name (keys %actions) {
495 33 my $action = $actions{$name};
496  
497 # Get the list of methods for Action
498 33 my @methods = $action->remoting_api($env);
499  
500 33 ▶ next ACTION unless @methods;
Branch: 1 branch
BranchTrueFalseTotal
unless @methods 7 26 33
501
502 26 $api{ $name } = [ @methods ];
503 };
504  
505 # Compile hashref
506 8 my $remoting_api = {
507 url => $config->router_path,
508 type => 'remoting',
509 actions => { %api },
510 };
511  
512 # Add timeout if it's defined
513 8 ▶ $remoting_api->{timeout} = $config->timeout
Branch: 1 branch
BranchTrueFalseTotal
if $config->timeout 1 7 8
514 if $config->timeout;
515  
516 # Add maxRetries if it's defined
517 8 ▶ $remoting_api->{maxRetries} = $config->max_retries
Branch: 1 branch
BranchTrueFalseTotal
if $config->max_retries 1 7 8
518 if $config->max_retries;
519  
520 # Add namespace if it's defined
521 8 ▶ $remoting_api->{namespace} = $config->namespace
Branch: 1 branch
BranchTrueFalseTotal
if $config->namespace 7 1 8
522 if $config->namespace;
523  
524 8 return $remoting_api;
525 }
526  
527 ### PRIVATE CLASS METHOD ###
528 #
529 # Returns POLLING_API definition hashref
530 #
531  
532 8 ▶sub _get_polling_api {
Subroutine _get_polling_api: called CC=4 SCAR=13.9
533 8 my ($self, $config, $env) = @_;
534
535 # Check if we have any poll handlers in our definitions
536 8 my $has_poll_handlers;
537
538 8 my %actions = %{ $self->{actions} };
539
540 ACTION:
541 8 foreach my $name (keys %actions) {
542 26 my $action = $actions{$name};
543 26 $has_poll_handlers = $action->has_pollHandlers($env);
544  
545 26 ▶ last ACTION if $has_poll_handlers;
Branch: 1 branch
BranchTrueFalseTotal
if $has_poll_handlers 5 21 26
546 };
547  
548 # No sense in setting up polling if there ain't no Event providers
549 8 ▶ return undef unless $has_poll_handlers; ## no critic
Branch: 1 branch
BranchTrueFalseTotal
unless $has_poll_handlers 3 5 8
550
551 # Got poll handlers, return definition hashref
552 return {
553 5 type => 'polling',
554 url => $config->poll_path,
555 };
556 }
557  
558 ### PRIVATE INSTANCE METHOD ###
559 #
560 # Make an Action name from a package name (strip namespace)
561 #
562  
563 60 ▶sub _get_action_name {
Subroutine _get_action_name: called CC=2 SCAR=7.4
564 60 my ($self, $action_name) = @_;
565
566 60 ▶ if ( $self->config->api_full_action_names ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->config->api_full_action_names) { } 0 60 60
567 0 $action_name =~ s/::/./g;
568 }
569 else {
570 60 $action_name =~ s/^.*:://;
571 }
572
573 60 return $action_name;
574 }
575  
576 27 1;
« ExtDirect/Request.pm ↑ Summary ExtDirect/Test/Util.pm »