GX/Controller.pm

filter: Statementstmt 13.0% 55 / 421 Branchbran 0.5% 1 / 190 Conditioncond 0.0% 0 / 54 MC/DCmcdc 0.0% 0 / 31 Subroutinesub 27.5% 16 / 58 Podpod 100% 16 / 16 totaltotal 11.4% 88 / 770 CC 131 SCAR 50.8
CC
131
Cov
8%
_setup_routes
506.0
_setup_config
342.0
_create_format_handler
272.0
CRAP 161.2
« GX/Context.pm ↑ Summary GX/View/Template.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Controller.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Controller;
7  
8 21 ▶use GX::Action;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 21 ▶use GX::Callback;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 21 ▶use GX::Callback::Hook;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 21 ▶use GX::Callback::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 21 ▶use GX::Callback::Queue;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 21 ▶use GX::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 21 ▶use GX::Meta::Constants qw( REGEX_CLASS_NAME );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 21 ▶use GX::Renderer;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 21 ▶use GX::Route::Dynamic;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 21 ▶use GX::Route::Static;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 21 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 # ----------------------------------------------------------------------------------------------------------------------
23 # Class setup
24 # ----------------------------------------------------------------------------------------------------------------------
25  
26 21 ▶use GX::Class ( code_attributes => [ qw( Action After Before Render ) ] );
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 21 extends 'GX::Component::Singleton';
29  
30 21 has 'actions' => (
31 isa => 'Hash',
32 initialize => 1,
33 accessors => {
34 '_get_action' => { type => 'get_value' },
35 '_set_action' => { type => 'set_value' },
36 '_get_actions' => { type => 'get_reference' },
37 '_get_action_names' => { type => 'get_keys' }
38 }
39 );
40  
41 21 has 'base_path' => (
42 isa => 'String',
43 initialize => 1,
44 initializer => '_initialize_base_path',
45 accessors => {
46 '_get_base_path' => { type => 'get' },
47 '_set_base_path' => { type => 'set' }
48 }
49 );
50  
51 21 has 'default_format' => (
52 isa => 'Scalar',
53 initialize => 1,
54 default => 'html',
55 accessors => {
56 '_get_default_format' => { type => 'get' },
57 '_set_default_format' => { type => 'set' }
58 }
59 );
60  
61 21 has 'filter_hooks' => (
62 isa => 'Hash',
63 initialize => 1,
64 accessors => {
65 '_get_filter_hook' => { type => 'get_value' },
66 '_set_filter_hook' => { type => 'set_value' },
67 '_get_filter_hooks' => { type => 'get_reference' }
68 }
69 );
70  
71 has 'name' => (
72 isa => 'Scalar',
73 initialize => 1,
74 20 ▶ initializer => sub { ( /^.+?::Controller::(.+)$/ )[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
75 21 accessors => {
76 '_get_name' => { type => 'get' }
77 }
78 );
79  
80 21 has 'post_dispatch_filter_hooks' => (
81 isa => 'Array',
82 initialize => 1,
83 accessors => {
84 '_get_post_dispatch_filter_hooks' => { type => 'get_reference' }
85 }
86 );
87  
88 21 has 'pre_dispatch_filter_hooks' => (
89 isa => 'Array',
90 initialize => 1,
91 accessors => {
92 '_get_pre_dispatch_filter_hooks' => { type => 'get_reference' }
93 }
94 );
95  
96 21 has 'renderers' => (
97 isa => 'Hash',
98 initialize => 1,
99 accessors => {
100 '_get_renderer' => { type => 'get_value' },
101 '_set_renderer' => { type => 'set_value' },
102 '_get_renderers' => { type => 'get_reference' }
103 }
104 );
105  
106 21 has 'routes' => (
107 isa => 'Array',
108 initialize => 1,
109 accessors => {
110 '_get_routes' => { type => 'get_reference' }
111 }
112 );
113  
114 21 build;
115  
116  
117 # ----------------------------------------------------------------------------------------------------------------------
118 # Export mechanism
119 # ----------------------------------------------------------------------------------------------------------------------
120  
121 21 __PACKAGE__->_install_import_method;
122  
123  
124 # ----------------------------------------------------------------------------------------------------------------------
125 # Public methods
126 # ----------------------------------------------------------------------------------------------------------------------
127  
128 0 ▶sub action {
Subroutine action: not called CC=1 SCAR=6.9
Pod documented
129  
130 0 return $_[0]->instance->_get_action( $_[1] );
131  
132 }
133  
134 0 ▶sub actions {
Subroutine actions: not called CC=1 SCAR=6.9
Pod documented
135  
136 0 return values %{$_[0]->instance->_get_actions};
137  
138 }
139  
140 0 ▶sub base_path {
Subroutine base_path: not called CC=1 SCAR=6.9
Pod documented
141  
142 0 return $_[0]->instance->_get_base_path;
143  
144 }
145  
146 0 ▶sub default_format {
Subroutine default_format: not called CC=1 SCAR=6.9
Pod documented
147  
148 0 return $_[0]->instance->_get_default_format;
149  
150 }
151  
152 0 ▶sub filter_hook {
Subroutine filter_hook: not called CC=1 SCAR=6.9
Pod documented
153  
154 0 return $_[0]->instance->_get_filter_hooks->{$_[1]};
155  
156 }
157  
158 0 ▶sub filter_hooks {
Subroutine filter_hooks: not called CC=1 SCAR=6.9
Pod documented
159  
160 0 return values %{$_[0]->instance->_get_filter_hooks};
161  
162 }
163  
164 0 ▶sub filters {
Subroutine filters: not called CC=1 SCAR=6.9
Pod documented
165  
166 0 return $_[0]->instance->_get_filters;
167  
168 }
169  
170 40 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
171  
172 40 return $_[0]->instance->_get_name;
173  
174 }
175  
176 0 ▶sub post_dispatch_filter_hooks {
Subroutine post_dispatch_filter_hooks: not called CC=1 SCAR=6.9
Pod documented
177  
178 0 return @{$_[0]->instance->_get_post_dispatch_filter_hooks};
179  
180 }
181  
182 0 ▶sub post_dispatch_filters {
Subroutine post_dispatch_filters: not called CC=1 SCAR=6.9
Pod documented
183  
184 0 return $_[0]->instance->_get_post_dispatch_filters;
185  
186 }
187  
188 0 ▶sub pre_dispatch_filter_hooks {
Subroutine pre_dispatch_filter_hooks: not called CC=1 SCAR=6.9
Pod documented
189  
190 0 return @{$_[0]->instance->_get_pre_dispatch_filter_hooks};
191  
192 }
193  
194 0 ▶sub pre_dispatch_filters {
Subroutine pre_dispatch_filters: not called CC=1 SCAR=6.9
Pod documented
195  
196 0 return $_[0]->instance->_get_pre_dispatch_filters;
197  
198 }
199  
200 0 ▶sub renderer {
Subroutine renderer: not called CC=5 SCAR=34.0
Pod documented
201  
202 0 my $self = shift->instance;
203  
204 0 ▶ if ( ! defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 0 0 0
205 0 complain "Missing argument";
206 }
207  
208 0 ▶ if ( blessed $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_[0])) { } 0 0 0
209  
210 0 ▶ if ( $_[0]->isa( 'GX::Action' ) && $_[0]->controller == $self ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->isa("GX::Action") and $_[0]->controller == $self) 0 0 0
Condition0%0/3
$_[0]->isa("GX::Action") and $_[0]->controller == $self
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0]->isa("GX::Action") and $_[0]->controller == $self
$_[0]->isa("GX::Action") $_[0]->controller == $self
Truth table0%0/3
A and B
A= $_[0]->isa("GX::Action")B= $_[0]->controller == $self
ABresult
0X0
100
111
211 0 return $self->_get_renderer( $_[0]->name );
212 }
213  
214 }
215 else {
216 0 return $self->_get_renderer( $_[0] );
217 }
218  
219 0 return undef;
220  
221 }
222  
223 0 ▶sub routes {
Subroutine routes: not called CC=1 SCAR=6.9
Pod documented
224  
225 0 return @{$_[0]->instance->_get_routes};
226  
227 }
228  
229  
230 # ----------------------------------------------------------------------------------------------------------------------
231 # Internal methods
232 # ----------------------------------------------------------------------------------------------------------------------
233  
234 0 ▶sub dispatch {
Subroutine dispatch: not called CC=4 SCAR=30.0
Pod documented
235  
236 0 my $self = shift;
237 0 my $context = shift;
238 0 my $action = shift;
239  
240 0 my $dispatch_stack = $context->dispatch_stack;
241  
242 0 my $dispatch_queue = $self->_create_dispatch_queue( $action );
243  
244 0 push @$dispatch_stack, [ $action, $dispatch_queue ];
245  
246 0 my $error;
247  
248 {
249  
250 0 local $@;
251  
252 0 eval {
253  
254 0 ▶ while ( my $callback = $dispatch_queue->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $callback = $dispatch_queue->next) 0 0 0
255 0 $callback->call( $context );
256 }
257  
258 };
259  
260 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
261 0 $error = $@;
262 }
263  
264 }
265  
266 0 ▶ if ( $error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
267 0 $self->handle_error( $context, $error );
268 }
269  
270 0 pop @$dispatch_stack;
271  
272 0 return;
273  
274 }
275  
276 0 ▶sub handle_error {
Subroutine handle_error: not called CC=1 SCAR=6.9
Pod documented
277  
278 0 my $self = shift;
279 0 my $context = shift;
280 0 my $error = shift;
281  
282 0 $self->application->handle_error( $context, $error );
283  
284 0 return;
285  
286 }
287  
288  
289 # ----------------------------------------------------------------------------------------------------------------------
290 # Private methods
291 # ----------------------------------------------------------------------------------------------------------------------
292  
293 0 ▶sub _add_action {
Subroutine _add_action: not called CC=2 SCAR=17.9
294  
295 0 my $self = shift;
296 0 my $action = shift;
297  
298 0 my $action_name = $action->name;
299  
300 0 ▶ if ( $self->_get_action( $action_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_get_action($action_name)) 0 0 0
301 0 throw "Cannot add action (duplicate action name: \"$action_name\")";
302 }
303  
304 0 $self->_set_action( $action_name => $action );
305  
306 0 return;
307  
308 }
309  
310 0 ▶sub _add_post_dispatch_filter_hook {
Subroutine _add_post_dispatch_filter_hook: not called CC=3 SCAR=24.8
311  
312 0 my $self = shift;
313 0 my $hook = shift;
314  
315 0 my $hook_name = $hook->name;
316  
317 0 ▶ if ( ! defined $hook_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hook_name) 0 0 0
318 0 throw "Cannot add post-dispatch filter hook (undefined hook name)";
319 }
320  
321 0 ▶ if ( $self->_get_filter_hook( $hook_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_get_filter_hook($hook_name)) 0 0 0
322 0 throw "Cannot add post-dispatch filter hook (duplicate hook name: \"$hook_name\")";
323 }
324  
325 0 $self->_set_filter_hook( $hook_name => $hook );
326  
327 0 push @{$self->_get_post_dispatch_filter_hooks}, $hook;
328  
329 0 return;
330  
331 }
332  
333 0 ▶sub _add_pre_dispatch_filter_hook {
Subroutine _add_pre_dispatch_filter_hook: not called CC=3 SCAR=24.8
334  
335 0 my $self = shift;
336 0 my $hook = shift;
337  
338 0 my $hook_name = $hook->name;
339  
340 0 ▶ if ( ! defined $hook_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hook_name) 0 0 0
341 0 throw "Cannot add pre-dispatch filter hook (undefined hook name)";
342 }
343  
344 0 ▶ if ( $self->_get_filter_hook( $hook_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_get_filter_hook($hook_name)) 0 0 0
345 0 throw "Cannot add pre-dispatch filter hook (duplicate hook name: \"$hook_name\")";
346 }
347  
348 0 $self->_set_filter_hook( $hook_name => $hook );
349  
350 0 push @{$self->_get_pre_dispatch_filter_hooks}, $hook;
351  
352 0 return;
353  
354 }
355  
356 0 ▶sub _add_route {
Subroutine _add_route: not called CC=1 SCAR=6.9
357  
358 0 my $self = shift;
359 0 my $route = shift;
360  
361 0 push @{$self->_get_routes}, $route;
362  
363 0 return;
364  
365 }
366  
367 0 ▶sub _auto_render_filter {
Subroutine _auto_render_filter: not called CC=9 SCAR=45.0
368  
369 0 my $self = shift;
370 0 my $context = shift;
371  
372 0 my $body = $context->response->body;
373  
374 0 ▶ if ( ! $body ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($body) 0 0 0
375 0 return;
376 }
377  
378 0 ▶ if ( $body->length || $body->readonly ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body->length or $body->readonly) 0 0 0
Condition0%0/3
$body->length or $body->readonly
l!l&&r!l&&!r
000
MC/DC0%0/2
$body->length or $body->readonly
$body->length $body->readonly
Truth table0%0/3
A or B
A= $body->lengthB= $body->readonly
ABresult
1X1
011
000
379 0 return;
380 }
381  
382 0 my $action = $context->action;
383  
384 0 ▶ if ( ! $action ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action) 0 0 0
385 0 return;
386 }
387  
388 0 my $renderer = $self->_get_renderer( $action->name );
389  
390 0 ▶ if ( ! $renderer ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($renderer) 0 0 0
391 0 return;
392 }
393  
394 0 ▶ my $format = $context->request->format // $self->_get_default_format;
Condition0%0/3
$context->request->format // $self->_get_default_format
l!l&&r!l&&!r
000
MC/DC0%0/2
$context->request->format // $self->_get_default_format
$context->request->format $self->_get_default_format
Truth table0%0/3
A // B
A= $context->request->formatB= $self->_get_default_format
ABresult
1X1
011
000
395  
396 0 ▶ if ( ! defined $format ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $format) 0 0 0
397 0 return;
398 }
399  
400 0 ▶ if ( $renderer->can_render( $format ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($renderer->can_render($format)) { } 0 0 0
401 0 $renderer->render( $format, context => $context );
402 }
403 else {
404 0 $context->send_response( status => 406 );
405 }
406  
407 0 return;
408  
409 }
410  
411 0 ▶sub _create_action {
Subroutine _create_action: not called CC=1 SCAR=6.9
412  
413 0 my $self = shift;
414 0 my $method = shift;
415  
416 0 return GX::Action->new( controller => $self, method => $method );
417  
418 }
419  
420 0 ▶sub _create_default_route {
Subroutine _create_default_route: not called CC=4 SCAR=30.0
421  
422 0 my $self = shift;
423 0 my $action = shift;
424  
425 0 my $path = $self->_get_base_path;
426  
427 0 ▶ if ( $action->name eq 'default' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action->name eq 'default') { } 0 0 0
428 0 ▶ chop $path if length( $path ) > 1 && substr( $path, -1 ) eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if length $path > 1 and substr($path, -1) eq "/" 0 0 0
Condition0%0/3
length $path > 1 and substr($path, -1) eq "/"
!ll&&!rl&&r
000
MC/DC0%0/2
length $path > 1 and substr($path, -1) eq "/"
length $path > 1 substr($path, -1) eq "/"
Truth table0%0/3
A and B
A= length $path > 1B= substr($path, -1) eq "/"
ABresult
0X0
100
111
429 }
430 else {
431 0 $path .= lc $action->name;
432 }
433  
434 0 return $self->_create_route(
435 class => 'GX::Route::Static',
436 action => $action,
437 path => $path
438 );
439  
440 }
441  
442 0 ▶sub _create_dispatch_queue {
Subroutine _create_dispatch_queue: not called CC=1 SCAR=6.9
443  
444 0 my $self = shift;
445 0 my $action = shift;
446  
447 0 my $queue = GX::Callback::Queue->new;
448  
449 0 $queue->add( $self->_get_pre_dispatch_filters, $action, $self->_get_post_dispatch_filters );
450  
451 0 return $queue;
452  
453 }
454  
455 0 ▶sub _create_filter {
Subroutine _create_filter: not called CC=1 SCAR=6.9
456  
457 0 my $self = shift;
458 0 my $method = shift;
459  
460 0 return GX::Callback::Method->new( invocant => $self, method => $method );
461  
462 }
463  
464 0 ▶sub _create_filter_hook {
Subroutine _create_filter_hook: not called CC=1 SCAR=6.9
465  
466 0 my $self = shift;
467 0 my $name = shift;
468  
469 0 return GX::Callback::Hook->new( name => $name );
470  
471 }
472  
473 0 ▶sub _create_format_handler {
Subroutine _create_format_handler: not called CC=16 SCAR=56.1
474  
475 0 my $self = shift;
476  
477 0 my $handler;
478  
479 0 ▶ if ( blessed $_[0] ) {
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($_[0])) { } 0 0 0
elsif (ref $_[0]) { } 0 0 0
elsif (defined $_[0]) { } 0 0 0
480  
481 0 ▶ if ( $_[0]->isa( 'GX::View' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[0]->isa('GX::View')) { } 0 0 0
elsif ($_[0]->isa('GX::Callback')) { } 0 0 0
482 0 $handler = GX::Callback::Method->new( invocant => $_[0], method => 'render' );
483 }
484 elsif ( $_[0]->isa( 'GX::Callback' ) ) {
485 0 $handler = $_[0];
486 }
487 else {
488 0 throw "Invalid handler definition";
489 }
490  
491 }
492 elsif ( ref $_[0] ) {
493  
494 0 ▶ if ( ref $_[0] eq 'ARRAY' || ref $_[0] eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY' or ref $_[0] eq 'HASH') { } 0 0 0
elsif (ref $_[0] eq 'CODE') { } 0 0 0
Condition0%0/3
ref $_[0] eq "ARRAY" or ref $_[0] eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq "ARRAY" or ref $_[0] eq "HASH"
ref $_[0] eq "ARRAY" ref $_[0] eq "HASH"
Truth table0%0/3
A or B
A= ref $_[0] eq "ARRAY"B= ref $_[0] eq "HASH"
ABresult
1X1
011
000
495  
496 0 my %args;
497  
498 0 ▶ if ( ref $_[0] eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 0 0
499  
500 0 ▶ if ( ! ( @{$_[0]} % 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$_[0];} % 2) { } 0 0 0
501 0 %args = @{$_[0]};
502 }
503 else {
504 0 throw "Invalid handler definition";
505 }
506  
507 }
508 else {
509 0 %args = %{$_[0]};
510 }
511  
512 0 my $view;
513  
514 0 ▶ if ( blessed $args{'view'} && $args{'view'}->isa( 'GX::View' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($args{'view'}) and $args{'view'}->isa('GX::View')) { } 0 0 0
elsif (defined $args{'view'}) { } 0 0 0
Condition0%0/3
builtin::blessed($args{"view"}) and $args{"view"}->isa("GX::View")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($args{"view"}) and $args{"view"}->isa("GX::View")
builtin::blessed($args{"view"}) $args{"view"}->isa("GX::View")
Truth table0%0/3
A and B
A= builtin::blessed($args{"view"})B= $args{"view"}->isa("GX::View")
ABresult
0X0
100
111
515 0 $view = $args{'view'};
516 }
517 elsif ( defined $args{'view'} ) {
518  
519 0 $view = $self->application->view( $args{'view'} );
520  
521 0 ▶ if ( ! $view ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($view) 0 0 0
522 0 throw "Invalid handler definition (unknown view \"$args{'view'}\")";
523 }
524  
525 }
526 else {
527 0 throw "Invalid handler definition (unspecified view)";
528 }
529  
530 0 delete $args{'view'};
531  
532 0 $handler = GX::Callback::Method->new(
533 invocant => $view,
534 method => 'render',
535 arguments => [ %args ]
536 );
537  
538 }
539 elsif ( ref $_[0] eq 'CODE' ) {
540 0 $handler = GX::Callback->new( $_[0] );
541 }
542 else {
543 0 throw "Invalid handler definition";
544 }
545  
546 }
547 elsif ( defined $_[0] ) {
548  
549 0 my $view = $self->application->view( $_[0] );
550  
551 0 ▶ if ( ! $view ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($view) 0 0 0
552 0 throw "Invalid handler definition (unknown view \"$_[0]\")";
553 }
554  
555 0 $handler = GX::Callback::Method->new( invocant => $view, method => 'render' );
556  
557 }
558 else {
559 0 throw "Invalid handler definition";
560 }
561  
562 0 return $handler;
563  
564 }
565  
566 0 ▶sub _create_renderer {
Subroutine _create_renderer: not called CC=6 SCAR=37.4
567  
568 0 my $self = shift;
569  
570 0 my $renderer = GX::Renderer->new;
571  
572 0 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 0 0 0
573  
574 0 ▶ my %handler_config = ref $_[0] eq 'HASH' ? %{$_[0]} : ( '*' => $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
575  
576 0 for my $format ( keys %handler_config ) {
577  
578 0 my $handler = eval { $self->_create_format_handler( $handler_config{$format} ) };
579  
580 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
581 0 GX::Exception->throw(
582 message => "Cannot create \"$format\" format handler",
583 subexception => $@
584 );
585 }
586  
587 0 ▶ if ( $handler ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) 0 0 0
588 0 $renderer->handler( $format => $handler );
589 }
590  
591 }
592  
593 }
594  
595 0 return $renderer;
596  
597 }
598  
599 0 ▶sub _create_route {
Subroutine _create_route: not called CC=14 SCAR=53.5
600  
601 0 my $self = shift;
602 0 my %args = @_;
603  
604 0 my $route_class;
605  
606 0 ▶ if ( exists $args{'class'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'class'}) { } 0 0 0
607  
608 0 ▶ if ( defined $args{'class'} && $args{'class'} =~ REGEX_CLASS_NAME ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'class'} and $args{'class'} =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/) { } 0 0 0
Condition0%0/3
defined $args{"class"} and $args{"class"} =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"class"} and $args{"class"} =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
defined $args{"class"} $args{"class"} =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
Truth table0%0/3
A and B
A= defined $args{"class"}B= $args{"class"} =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
ABresult
0X0
100
111
609 0 $route_class = delete $args{'class'};
610 }
611 else {
612 0 throw "Invalid route class";
613 }
614  
615 }
616 else {
617  
618 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'path'} and $args{'path'} =~ /[*{}]+/ or defined $args{'host'} and $args{'host'} =~ /[*{}]+/ or exists $args{'methods'} or exists $args{'schemes'}) { } 0 0 0
Condition0%0/15
defined $args{"path"} and $args{"path"} =~ /[*{}]+/ or defined $args{"host"} and $args{"host"} =~ /[*{}]+/ or exists $args{"methods"} or exists $args{"schemes"}
l!l&&r!l&&!r
000
defined $args{"path"} and $args{"path"} =~ /[*{}]+/ or defined $args{"host"} and $args{"host"} =~ /[*{}]+/ or exists $args{"methods"}
l!l&&r!l&&!r
000
defined $args{"path"} and $args{"path"} =~ /[*{}]+/ or defined $args{"host"} and $args{"host"} =~ /[*{}]+/
l!l&&r!l&&!r
000
defined $args{"path"} and $args{"path"} =~ /[*{}]+/
!ll&&!rl&&r
000
defined $args{"host"} and $args{"host"} =~ /[*{}]+/
!ll&&!rl&&r
000
MC/DC0%0/6
defined $args{"path"} and $args{"path"} =~ /[*{}]+/ or defined $args{"host"} and $args{"host"} =~ /[*{}]+/ or exists $args{"methods"} or exists $args{"schemes"}
defined $args{"path"} $args{"path"} =~ /[*{}]+/ defined $args{"host"} $args{"host"} =~ /[*{}]+/ exists $args{"methods"} exists $args{"schemes"}
Truth table0%0/15
A and B or C and D or E or F
A= defined $args{"path"}B= $args{"path"} =~ /[*{}]+/C= defined $args{"host"}D= $args{"host"} =~ /[*{}]+/E= exists $args{"methods"}F= exists $args{"schemes"}
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X1X1
0X101X1
100X1X1
10101X1
0X0X011
0X10011
100X011
1010011
0X0X000
0X10000
100X000
1010000
619 ( defined $args{'path'} && $args{'path'} =~ /[*{}]+/ ) ||
620 ( defined $args{'host'} && $args{'host'} =~ /[*{}]+/ ) ||
621 exists $args{'methods'} ||
622 exists $args{'schemes'}
623 ) {
624 0 $route_class = 'GX::Route::Dynamic';
625 }
626 else {
627 0 $route_class = 'GX::Route::Static';
628 }
629  
630 }
631  
632 0 ▶ if ( defined $args{'path'} && ! ref $args{'path'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"path"} and not ref $args{"path"}) 0 0 0
Condition0%0/3
defined $args{"path"} and not ref $args{"path"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"path"} and not ref $args{"path"}
defined $args{"path"} not ref $args{"path"}
Truth table0%0/3
A and not(B)
A= defined $args{"path"}B= not ref $args{"path"}
ABresult
0X0
100
111
633  
634 0 ▶ if ( $args{'path'} =~ s/^\.\/// || $args{'path'} !~ /^\// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"path"} =~ s[^\./][] or not $args{"path"} =~ m[^/]) 0 0 0
Condition0%0/3
$args{"path"} =~ s[^\./][] or not $args{"path"} =~ m[^/]
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"path"} =~ s[^\./][] or not $args{"path"} =~ m[^/]
$args{"path"} =~ s[^\./][] not $args{"path"} =~ m[^/]
Truth table0%0/3
A or not(B)
A= $args{"path"} =~ s[^\./][]B= not $args{"path"} =~ m[^/]
ABresult
1X1
011
000
635 0 $args{'path'} = $self->_get_base_path . $args{'path'};
636 }
637  
638 }
639  
640 0 return $route_class->new( %args );
641  
642 }
643  
644 0 ▶sub _deploy {
Subroutine _deploy: not called CC=2 SCAR=17.9
645  
646 0 my $self = shift;
647  
648 0 $self->_deploy_renderers;
649  
650 0 ▶ if ( $self->_get_config->{'create_default_renderers'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_get_config->{"create_default_renderers"}) 0 0 0
651 0 $self->_deploy_default_renderers;
652 }
653  
654 0 return;
655  
656 }
657  
658 0 ▶sub _deploy_default_renderers {
Subroutine _deploy_default_renderers: not called CC=11 SCAR=48.8
659  
660 0 my $self = shift;
661  
662 0 ▶ my @views = grep { $_->isa( 'GX::View::Template' ) } $self->application->views or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@views) = grep({$_->isa("GX::View::Template");} $self->application->views) or return 0 0 0
663  
664 0 my $template_regex = do {
665  
666 0 my $name = $self->_get_name;
667  
668 0 ▶ my $pattern =
Branch: 1 branch
BranchTrueFalseTotal
$name ne 'Root' ? : 0 0 0
669 '^' .
670 ( $name ne 'Root' ? join( '/', split( /::/, $name ) ) . '/' : '' ) .
671 '([^.]+)(?:\.([^.]+))?\.[^.]+?' .
672 '$';
673  
674 0 qr/$pattern/;
675  
676 };
677  
678 0 for my $view ( @views ) {
679  
680 0 for my $template ( $view->templates ) {
681  
682 0 ▶ $template =~ $template_regex or next;
Branch: 1 branch
BranchTrueFalseTotal
$template =~ /$template_regex/ or next 0 0 0
683  
684 0 my $action_name = $1;
685 0 my $format = $2;
686  
687 0 ▶ my $action = $self->_get_action( $action_name ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $action = $self->_get_action($action_name) or next 0 0 0
688  
689 0 ▶ if ( ! defined $format ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $format) 0 0 0
690 0 $format = '*';
691 }
692  
693 0 my $renderer = $self->_get_renderer( $action_name );
694  
695 0 ▶ if ( ! $renderer ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($renderer) 0 0 0
696 0 ▶ $renderer = $self->_create_renderer or next;
Branch: 1 branch
BranchTrueFalseTotal
$renderer = $self->_create_renderer or next 0 0 0
697 0 $self->_set_renderer( $action_name => $renderer );
698 }
699  
700 0 ▶ next if $renderer->handler( $format );
Branch: 1 branch
BranchTrueFalseTotal
if $renderer->handler($format) 0 0 0
701  
702 0 $renderer->handler(
703 $format => GX::Callback::Method->new(
704 invocant => $view,
705 method => 'render',
706 arguments => [ template => $template ]
707 )
708 );
709  
710 }
711  
712 }
713  
714 0 return;
715  
716 }
717  
718 0 ▶sub _deploy_renderers {
Subroutine _deploy_renderers: not called CC=13 SCAR=52.0
719  
720 0 my $self = shift;
721  
722 0 my $config = $self->_get_config;
723  
724 0 ▶ if ( defined $config->{'render_all'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"render_all"}) 0 0 0
725  
726 0 my $renderer = eval { $self->_create_renderer( $config->{'render_all'} ) };
727  
728 0 ▶ if ( ! $renderer ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($renderer) 0 0 0
729 0 GX::Exception->throw(
730 message => "Cannot create renderer",
731 subexception => $@
732 );
733 }
734  
735 0 for my $action_name ( $self->_get_action_names ) {
736  
737 0 ▶ if ( my $existing_renderer = $self->_get_renderer( $action_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $existing_renderer = $self->_get_renderer($action_name)) { } 0 0 0
738 0 $existing_renderer->merge( $renderer );
739 }
740 else {
741 0 $self->_set_renderer( $action_name => $renderer->clone );
742 }
743  
744 }
745  
746 }
747  
748 0 ▶ if ( defined $config->{'render'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"render"}) 0 0 0
749  
750 0 ▶ if ( ref $config->{'render'} ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $config->{"render"} ne "HASH") 0 0 0
751 0 throw "Invalid option (\"render\" must be a hash reference)";
752 }
753  
754 0 ▶ while ( my ( $action_name, $render_directive ) = each %{$config->{'render'}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$config{"render"};}) 0 0 0
755  
756 0 ▶ if ( ! $self->_get_action( $action_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_get_action($action_name)) 0 0 0
757 0 throw "Cannot create renderer ($self has no \"$action_name\" action)";
758 }
759  
760 0 my $renderer;
761  
762 0 ▶ if ( blessed $render_directive && $render_directive->isa( 'GX::Renderer' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($render_directive) and $render_directive->isa('GX::Renderer')) { } 0 0 0
Condition0%0/3
builtin::blessed($render_directive) and $render_directive->isa("GX::Renderer")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($render_directive) and $render_directive->isa("GX::Renderer")
builtin::blessed($render_directive) $render_directive->isa("GX::Renderer")
Truth table0%0/3
A and B
A= builtin::blessed($render_directive)B= $render_directive->isa("GX::Renderer")
ABresult
0X0
100
111
763 0 $renderer = $render_directive;
764 }
765 else {
766  
767 0 $renderer = eval { $self->_create_renderer( $render_directive ) };
768  
769 0 ▶ if ( ! $renderer ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($renderer) 0 0 0
770 0 GX::Exception->throw(
771 message => "Cannot create renderer for action \"$action_name\"",
772 subexception => $@
773 );
774 }
775  
776 }
777  
778 0 ▶ if ( my $existing_renderer = $self->_get_renderer( $action_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $existing_renderer = $self->_get_renderer($action_name)) { } 0 0 0
779 0 $existing_renderer->merge( $renderer );
780 }
781 else {
782 0 $self->_set_renderer( $action_name => $renderer );
783 }
784  
785 }
786  
787 }
788  
789 0 return;
790  
791 }
792  
793 0 ▶sub _get_filters {
Subroutine _get_filters: not called CC=1 SCAR=6.9
794  
795 0 return map { $_->all } values %{$_[0]->_get_filter_hooks};
796  
797 }
798  
799 0 ▶sub _get_post_dispatch_filters {
Subroutine _get_post_dispatch_filters: not called CC=1 SCAR=6.9
800  
801 0 return map { $_->all } @{$_[0]->_get_post_dispatch_filter_hooks};
802  
803 }
804  
805 0 ▶sub _get_pre_dispatch_filters {
Subroutine _get_pre_dispatch_filters: not called CC=1 SCAR=6.9
806  
807 0 return map { $_->all } @{$_[0]->_get_pre_dispatch_filter_hooks};
808  
809 }
810  
811 20 ▶sub _initialize_base_path {
Subroutine _initialize_base_path: called CC=2 SCAR=7.1
812  
813 20 my $self = shift;
814  
815 20 my $name = $self->_get_name;
816  
817 20 ▶ return $name eq 'Root' ? '/' : '/' . join( '/', split( '::', lc $name ) ) . '/';
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'Root' ? : 0 20 20
818  
819 }
820  
821 0 ▶sub _initialize_config {
Subroutine _initialize_config: not called CC=1 SCAR=6.9
822  
823 return {
824 0 'auto_render' => 1,
825 'create_default_renderers' => 1,
826 'create_default_routes' => 1,
827 'inherit_actions' => 1,
828 'inherit_filters' => 1,
829 'post_dispatch_filter_hooks' => [ qw( Render After ) ],
830 'pre_dispatch_filter_hooks' => [ qw( Before ) ],
831 'render' => undef,
832 'render_all' => undef,
833 'routes' => undef
834 };
835  
836 }
837  
838 0 ▶sub _setup {
Subroutine _setup: not called CC=1 SCAR=6.9
839  
840 0 my $self = shift;
841 0 my $config = shift;
842  
843 0 $self->SUPER::_setup( $config );
844  
845 0 $self->_setup_filter_hooks;
846 0 $self->_setup_filters;
847 0 $self->_setup_auto_render_filter;
848 0 $self->_setup_actions;
849 0 $self->_setup_routes;
850  
851 0 return;
852  
853 }
854  
855 0 ▶sub _setup_actions {
Subroutine _setup_actions: not called CC=5 SCAR=34.0
856  
857 0 my $self = shift;
858  
859 0 ▶ my @methods = $self->_get_config->{'inherit_actions'} ? $self->meta->all_methods : $self->meta->methods;
Branch: 1 branch
BranchTrueFalseTotal
$self->_get_config->{'inherit_actions'} ? : 0 0 0
860  
861 METHOD:
862 0 for my $method ( @methods ) {
863  
864 0 for my $code_attribute ( $method->code_attributes ) {
865  
866 0 ▶ if ( $code_attribute =~ /^Action(?:\(.*\))?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_attribute =~ /^Action(?:\(.*\))?$/) 0 0 0
867 0 $self->_add_action( $self->_create_action( $method->name ) );
868 0 next METHOD;
869 }
870  
871 }
872  
873 }
874  
875 0 return;
876  
877 }
878  
879 0 ▶sub _setup_auto_render_filter {
Subroutine _setup_auto_render_filter: not called CC=3 SCAR=24.8
880  
881 0 my $self = shift;
882  
883 0 ▶ if ( $self->_get_config->{'auto_render'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_get_config->{"auto_render"}) 0 0 0
884  
885 0 ▶ if ( my $hook = $self->_get_filter_hook( 'Render' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hook = $self->_get_filter_hook("Render")) 0 0 0
886 0 $hook->add( $self->_create_filter( '_auto_render_filter' ) );
887 }
888  
889 }
890  
891 0 return;
892  
893 }
894  
895 0 ▶sub _setup_config {
Subroutine _setup_config: not called CC=18 SCAR=58.3
896  
897 0 my $self = shift;
898 0 my $args = shift;
899  
900 0 my $config = $self->_get_config;
901  
902 0 for my $option ( qw(
903 render_all
904 ) ) {
905 0 ▶ next unless exists $args->{$option};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{$option} 0 0 0
906 0 $config->{$option} = delete $args->{$option};
907 }
908  
909 0 for my $option ( qw(
910 auto_render
911 create_default_renderers
912 create_default_routes
913 inherit_actions
914 inherit_filters
915 ) ) {
916 0 ▶ next unless exists $args->{$option};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{$option} 0 0 0
917 0 ▶ $config->{$option} = delete $args->{$option} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $args->{$option} ? : 0 0 0
918 }
919  
920 0 for my $option ( qw(
921 render
922 ) ) {
923 0 ▶ next unless exists $args->{$option};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{$option} 0 0 0
924 0 ▶ ref $args->{$option} eq 'HASH' or throw "Invalid option (\"$option\" must be a hash reference)";
Branch: 1 branch
BranchTrueFalseTotal
ref $args->{$option} eq "HASH" or &throw(qq[Invalid option ("$option" must be a hash reference)]) 0 0 0
925 0 $config->{$option} = delete $args->{$option};
926 }
927  
928 0 ▶ if ( exists $args->{'routes'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"routes"}) 0 0 0
929  
930 0 ▶ if ( ref $args->{'routes'} eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $args->{'routes'} eq 'ARRAY') { } 0 0 0
elsif (ref $args->{'routes'} eq 'HASH') { } 0 0 0
931 0 $config->{'routes'} = delete $args->{'routes'};
932 }
933 elsif ( ref $args->{'routes'} eq 'HASH' ) {
934 0 $config->{'routes'} = [ %{ delete $args->{'routes'} } ];
935 }
936 else {
937 0 throw "Invalid option (\"routes\" must be an array reference or a hash reference)";
938 }
939  
940 }
941  
942 0 ▶ if ( exists $args->{'base_path'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"base_path"}) 0 0 0
943  
944 0 my $path = delete $args->{'base_path'};
945  
946 0 ▶ if ( ! defined $path || ! length $path || substr( $path, 0, 1 ) ne '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $path && length $path or substr($path, 0, 1) ne "/") 0 0 0
Condition0%0/6
not defined $path && length $path or substr($path, 0, 1) ne "/"
l!l&&r!l&&!r
000
defined $path && length $path
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $path && length $path or substr($path, 0, 1) ne "/"
defined $path length $path substr($path, 0, 1) ne "/"
Truth table0%0/4
not(A && B) or C
A= defined $pathB= length $pathC= substr($path, 0, 1) ne "/"
ABCresult
0XX1
10X1
1111
1100
947 0 throw "Invalid option (\"base_path\" must be an absolute path)";
948 }
949  
950 0 ▶ $path .= '/' if substr( $path, -1 ) ne '/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($path, -1) ne "/" 0 0 0
951  
952 0 $self->{'base_path'} = $path;
953  
954 }
955  
956 0 ▶ if ( exists $args->{'default_format'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"default_format"}) 0 0 0
957 0 $self->{'default_format'} = delete $args->{'default_format'};
958 }
959  
960 0 $self->SUPER::_setup_config( $args );
961  
962 0 return;
963  
964 }
965  
966 0 ▶sub _setup_filter_hooks {
Subroutine _setup_filter_hooks: not called CC=3 SCAR=24.8
967  
968 0 my $self = shift;
969  
970 0 for my $hook_name ( @{$self->_get_config->{'pre_dispatch_filter_hooks'}} ) {
971 0 $self->_add_pre_dispatch_filter_hook( $self->_create_filter_hook( $hook_name ) );
972 }
973  
974 0 for my $hook_name ( @{$self->_get_config->{'post_dispatch_filter_hooks'}} ) {
975 0 $self->_add_post_dispatch_filter_hook( $self->_create_filter_hook( $hook_name ) );
976 }
977  
978 0 return;
979  
980 }
981  
982 0 ▶sub _setup_filters {
Subroutine _setup_filters: not called CC=5 SCAR=34.0
983  
984 0 my $self = shift;
985  
986 0 ▶ my @methods = $self->_get_config->{'inherit_filters'} ? $self->meta->all_methods : $self->meta->methods;
Branch: 1 branch
BranchTrueFalseTotal
$self->_get_config->{'inherit_filters'} ? : 0 0 0
987  
988 0 @methods = sort { $a->name cmp $b->name } @methods;
989  
990 0 for my $method ( @methods ) {
991  
992 0 for my $code_attribute ( $method->code_attributes ) {
993  
994 0 ▶ if ( my $hook = $self->_get_filter_hook( $code_attribute ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hook = $self->_get_filter_hook($code_attribute)) 0 0 0
995 0 $hook->add( $self->_create_filter( $method->name ) );
996 }
997  
998 }
999  
1000 }
1001  
1002 0 return;
1003  
1004 }
1005  
1006 0 ▶sub _setup_routes {
Subroutine _setup_routes: not called CC=22 SCAR=62.3
1007  
1008 0 my $self = shift;
1009  
1010 0 my $config = $self->_get_config;
1011  
1012 0 my %routed_actions;
1013  
1014 ACTION:
1015 0 for my $action_name ( sort $self->_get_action_names ) {
1016  
1017 0 my $action = $self->_get_action( $action_name );
1018  
1019 0 for my $code_attribute ( attributes::get( $action->code ) ) {
1020  
1021 0 ▶ if ( $code_attribute =~ /^Action\((.+)\)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_attribute =~ /^Action\((.+)\)$/) 0 0 0
1022  
1023 0 my @paths;
1024  
1025 0 eval "\@paths = ( $1 )";
1026  
1027 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1028 0 throw "Invalid :Action attribute for method \"$action_name\"";
1029 }
1030  
1031 PATH:
1032 0 for my $path ( @paths ) {
1033  
1034 0 $routed_actions{$action_name}++;
1035  
1036 0 my $route = eval {
1037 0 $self->_create_route( action => $action, path => $path );
1038 };
1039  
1040 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1041 0 GX::Exception->throw(
1042 message => "Cannot create route for action \"$action_name\"",
1043 subexception => $@
1044 );
1045 }
1046  
1047 0 ▶ if ( $route ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($route) 0 0 0
1048 0 $self->_add_route( $route );
1049 }
1050  
1051 }
1052  
1053 0 next ACTION;
1054  
1055 }
1056  
1057 }
1058  
1059 }
1060  
1061 0 ▶ if ( $config->{'routes'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"routes"}) 0 0 0
1062  
1063 0 my @routes_config = @{$config->{'routes'}};
1064  
1065 0 ▶ while ( @routes_config ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@routes_config) 0 0 0
1066  
1067 0 my $action_name = shift @routes_config;
1068 0 my $route_config = shift @routes_config;
1069  
1070 0 ▶ if ( ! defined $action_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $action_name) 0 0 0
1071 0 throw "Invalid route definition (undefined action name)";
1072 }
1073  
1074 0 my $action = $self->_get_action( $action_name );
1075  
1076 0 ▶ if ( ! $action ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action) 0 0 0
1077 0 throw "Invalid route definition ($self has no \"$action_name\" action)";
1078 }
1079  
1080 0 $routed_actions{$action_name}++;
1081  
1082 0 ▶ next unless defined $route_config;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $route_config 0 0 0
1083  
1084 0 ▶ if ( blessed $route_config && $route_config->isa( 'GX::Route' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($route_config) and $route_config->isa('GX::Route')) { } 0 0 0
Condition0%0/3
builtin::blessed($route_config) and $route_config->isa("GX::Route")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($route_config) and $route_config->isa("GX::Route")
builtin::blessed($route_config) $route_config->isa("GX::Route")
Truth table0%0/3
A and B
A= builtin::blessed($route_config)B= $route_config->isa("GX::Route")
ABresult
0X0
100
111
1085 0 $self->_add_route( $route_config );
1086 }
1087 else {
1088  
1089 0 my $route = eval {
1090 0 ▶ $self->_create_route(
Branch: 1 branch
BranchTrueFalseTotal
ref $route_config eq 'HASH' ? : 0 0 0
1091 ( ref $route_config eq 'HASH' ? %$route_config : ( path => $route_config ) ),
1092 action => $action
1093 );
1094 };
1095  
1096 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1097 0 GX::Exception->throw(
1098 message => "Cannot create route for action \"$action_name\"",
1099 subexception => $@
1100 );
1101 }
1102  
1103 0 ▶ if ( $route ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($route) 0 0 0
1104 0 $self->_add_route( $route );
1105 }
1106  
1107 }
1108  
1109 }
1110  
1111 }
1112  
1113 0 ▶ if ( $config->{'create_default_routes'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"create_default_routes"}) 0 0 0
1114  
1115 0 for my $action_name ( sort $self->_get_action_names ) {
1116  
1117 0 ▶ next if $routed_actions{$action_name};
Branch: 1 branch
BranchTrueFalseTotal
if $routed_actions{$action_name} 0 0 0
1118  
1119 0 my $route = $self->_create_default_route( $self->_get_action( $action_name ) );
1120  
1121 0 ▶ if ( $route ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($route) 0 0 0
1122 0 $self->_add_route( $route );
1123 }
1124  
1125 }
1126  
1127 }
1128  
1129 0 return;
1130  
1131 }
1132  
1133 20 ▶sub _validate_class_name {
Subroutine _validate_class_name: called CC=1 SCAR=0.0
1134  
1135 20 return $_[1] =~ /^(?:[_a-zA-Z]\w*::)+?Controller(?:::[_a-zA-Z]\w*)+$/;
1136  
1137 }
1138  
1139  
1140 21 1;
1141  
1142 __END__
« GX/Context.pm ↑ Summary GX/View/Template.pm »