GX/Router.pm

filter: Statementstmt 47.2% 103 / 218 Branchbran 24.5% 26 / 106 Conditioncond 13.0% 6 / 46 MC/DCmcdc 4.0% 1 / 25 Subroutinesub 66.6% 18 / 27 Podpod 100% 8 / 8 totaltotal 37.6% 162 / 430 CC 75 SCAR 45.1
CC
75
Cov
36%
_create_route
380.0
_deploy_routes
90.0
_setup_config
45.2
CRAP 91.2
« GX/SQL/Builder.pm ↑ Summary GX/Session.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Router.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Router;
7  
8 2 ▶use GX::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use GX::Meta::Constants qw( REGEX_CLASS_NAME );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use GX::Route::Dynamic;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use GX::Route::Static;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use GX::Route::Static::Compiled;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 # ----------------------------------------------------------------------------------------------------------------------
18 # Class setup
19 # ----------------------------------------------------------------------------------------------------------------------
20  
21 2 ▶use GX::Class ( extends => 'GX::Component::Singleton' );
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 has 'compiled_routes' => (
24 isa => 'Scalar',
25 initialize => 0,
26 initializer => '_compile_routes',
27 accessors => {
28 '_get_compiled_routes' => { type => 'get' },
29 '_set_compiled_routes' => { type => 'set' },
30 '_clear_compiled_routes' => { type => 'clear' }
31 }
32 );
33  
34 2 has 'default_action' => (
35 isa => 'Scalar',
36 initialize => 1,
37 accessors => {
38 '_get_default_action' => { type => 'get' },
39 '_set_default_action' => { type => 'set' }
40 }
41 );
42  
43 2 has 'reversible_routes' => (
44 isa => 'Hash',
45 initialize => 1,
46 accessors => {
47 '_get_reversible_routes' => { type => 'get_reference' }
48 }
49 );
50  
51 2 has 'routes' => (
52 isa => 'Array',
53 initialize => 1,
54 accessors => {
55 '_get_routes' => { type => 'get_reference' }
56 }
57 );
58  
59 2 build;
60  
61  
62 # ----------------------------------------------------------------------------------------------------------------------
63 # Export mechanism
64 # ----------------------------------------------------------------------------------------------------------------------
65  
66 2 __PACKAGE__->_install_import_method;
67  
68  
69 # ----------------------------------------------------------------------------------------------------------------------
70 # Public methods
71 # ----------------------------------------------------------------------------------------------------------------------
72  
73 10 ▶sub add_route {
Subroutine add_route: called CC=4 SCAR=15.8
Pod documented
74  
75 10 my $self = shift->instance;
76 10 my $route = shift;
77  
78 10 ▶ if ( ! defined $route ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $route) 0 10 10
79 0 complain "Missing argument";
80 }
81  
82 10 ▶ if ( ! blessed $route || ! $route->isa( 'GX::Route' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($route) and $route->isa("GX::Route")) 0 10 10
Condition33%1/3
builtin::blessed($route) and $route->isa("GX::Route")
!ll&&!rl&&r
0010
MC/DC0%0/2
builtin::blessed($route) and $route->isa("GX::Route")
builtin::blessed($route) $route->isa("GX::Route")
Truth table33%1/3
A and B
A= builtin::blessed($route)B= $route->isa("GX::Route")
ABresult
0X0
100
111
83 0 complain "Invalid argument";
84 }
85  
86 10 $self->_add_route( $route );
87  
88 10 $self->_clear_compiled_routes;
89  
90 10 return;
91  
92 }
93  
94 0 ▶sub default_action {
Subroutine default_action: not called CC=1 SCAR=6.9
Pod documented
95  
96 0 return $_[0]->instance->_get_default_action;
97  
98 }
99  
100 0 ▶sub match {
Subroutine match: not called CC=3 SCAR=24.8
Pod documented
101  
102 0 my $self = shift->instance;
103 0 my $context = shift;
104  
105 0 for my $route ( @{$self->_get_compiled_routes} ) {
106 0 ▶ return $route->match( $context ) // next;
Condition0%0/2
$route->match($context) // (next)
l!l
00
MC/DC0%0/1
$route->match($context) // (next)
$route->match($context)
Truth table0%0/2
A
A= $route->match($context)
Aresult
11
00
107 }
108  
109 0 return undef;
110  
111 }
112  
113 20 ▶sub path_for_action {
Subroutine path_for_action: called CC=10 SCAR=29.0
Pod documented
114  
115 20 my $self = shift->instance;
116 20 ▶ my %args = ( @_ == 1 ) ? ( 'action' => $_[0] ) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 20 0 20
117  
118 20 ▶ if ( ! defined $args{'action'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"action"}) 0 20 20
119 0 complain "Missing argument (\"action\")";
120 }
121  
122 20 ▶ if ( ! blessed $args{'action'} || ! $args{'action'}->isa( 'GX::Action' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($args{"action"}) and $args{"action"}->isa("GX::Action")) 0 20 20
Condition33%1/3
builtin::blessed($args{"action"}) and $args{"action"}->isa("GX::Action")
!ll&&!rl&&r
0020
MC/DC0%0/2
builtin::blessed($args{"action"}) and $args{"action"}->isa("GX::Action")
builtin::blessed($args{"action"}) $args{"action"}->isa("GX::Action")
Truth table33%1/3
A and B
A= builtin::blessed($args{"action"})B= $args{"action"}->isa("GX::Action")
ABresult
0X0
100
111
123 0 complain "Invalid argument (\"action\" must be a GX::Action object)";
124 }
125  
126 20 ▶ if ( defined $args{'parameters'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"parameters"}) 0 20 20
127  
128 0 ▶ if ( ref $args{'parameters'} ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"parameters"} ne "HASH") 0 0 0
129 0 complain "Invalid argument (\"parameters\" must be a hash reference)";
130 }
131  
132 }
133  
134 20 my $route = $self->_reversible_route_for_action( $args{'action'} );
135  
136 20 ▶ if ( ! $route ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($route) 10 10 20
137 10 return undef;
138 }
139  
140 10 my $path = eval {
141 0 ▶ $route->construct_path( $args{'parameters'} ? %{$args{'parameters'}} : () );
Branch: 1 branch
BranchTrueFalseTotal
$args{'parameters'} ? : 0 10 10
142 };
143  
144 10 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 10 10
145 0 complain $@;
146 }
147  
148 10 return $path;
149  
150 }
151  
152 10 ▶sub remove_route {
Subroutine remove_route: called CC=5 SCAR=18.7
Pod documented
153  
154 10 my $self = shift->instance;
155 10 my $route = shift;
156  
157 10 ▶ if ( ! defined $route ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $route) 0 10 10
158 0 complain "Missing argument";
159 }
160  
161 10 ▶ if ( ! blessed $route || ! $route->isa( 'GX::Route' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($route) and $route->isa("GX::Route")) 0 10 10
Condition33%1/3
builtin::blessed($route) and $route->isa("GX::Route")
!ll&&!rl&&r
0010
MC/DC0%0/2
builtin::blessed($route) and $route->isa("GX::Route")
builtin::blessed($route) $route->isa("GX::Route")
Truth table33%1/3
A and B
A= builtin::blessed($route)B= $route->isa("GX::Route")
ABresult
0X0
100
111
162 0 complain "Invalid argument";
163 }
164  
165 10 ▶ $self->_remove_route( $route ) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_remove_route($route) or return 10 0 10
166  
167 10 $self->_clear_compiled_routes;
168  
169 10 return 1;
170  
171 }
172  
173 23 ▶sub routes {
Subroutine routes: called CC=1 SCAR=0.0
Pod documented
174  
175 23 return @{$_[0]->instance->_get_routes};
176  
177 }
178  
179 20 ▶sub uri_for_action {
Subroutine uri_for_action: called CC=7 SCAR=21.0
Pod documented
180  
181 20 my $self = shift->instance;
182 20 ▶ my %args = ( @_ == 1 ) ? ( 'action' => $_[0] ) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 10 10 20
183  
184 20 my $action = delete $args{'action'};
185  
186 20 ▶ if ( ! defined $action ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $action) 0 20 20
187 0 complain "Missing argument (\"action\")";
188 }
189  
190 20 ▶ if ( ! blessed $action || ! $action->isa( 'GX::Action' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($action) and $action->isa("GX::Action")) 0 20 20
Condition33%1/3
builtin::blessed($action) and $action->isa("GX::Action")
!ll&&!rl&&r
0020
MC/DC0%0/2
builtin::blessed($action) and $action->isa("GX::Action")
builtin::blessed($action) $action->isa("GX::Action")
Truth table33%1/3
A and B
A= builtin::blessed($action)B= $action->isa("GX::Action")
ABresult
0X0
100
111
191 0 complain "Invalid argument (\"action\" must be a GX::Action object)";
192 }
193  
194 20 my $route = $self->_reversible_route_for_action( $action );
195  
196 20 ▶ if ( ! $route ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($route) 10 10 20
197 10 return undef;
198 }
199  
200 10 my $uri = eval {
201 10 $route->construct_uri( %args );
202 };
203  
204 10 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 10 10
205 0 complain $@;
206 }
207  
208 10 return $uri;
209  
210 }
211  
212  
213 # ----------------------------------------------------------------------------------------------------------------------
214 # Handlers
215 # ----------------------------------------------------------------------------------------------------------------------
216  
217 0 ▶sub resolve :Handler( ResolveActions ) {
Subroutine resolve: not called CC=6 SCAR=37.4
Pod documented
218  
219 0 my $self = shift;
220 0 my $context = shift;
221  
222 0 my $action;
223  
224 0 ▶ if ( my $match = $self->match( $context ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $match = $self->match($context)) { } 0 0 0
225  
226 0 $action = $match->action;
227  
228 0 ▶ if ( my $parameters = $match->parameters ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parameters = $match->parameters) 0 0 0
229 0 $context->request->path_parameters( $parameters );
230 }
231  
232 0 ▶ if ( defined( my $format = $match->format ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $format = $match->format)) 0 0 0
233 0 $context->request->format( $format );
234 }
235  
236 }
237 else {
238 0 $action = $self->_get_default_action;
239 }
240  
241 0 ▶ if ( $action ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action) { } 0 0 0
242  
243 0 ▶ if ( my $action_queue = $context->action_queue ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $action_queue = $context->action_queue) 0 0 0
244 0 $action_queue->add( $action );
245 }
246  
247 }
248 else {
249 0 $context->send_response( status => 404 );
250 }
251  
252 0 return;
253  
254 2 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
255  
256  
257 # ----------------------------------------------------------------------------------------------------------------------
258 # Private methods
259 # ----------------------------------------------------------------------------------------------------------------------
260  
261 10 ▶sub _add_route {
Subroutine _add_route: called CC=2 SCAR=7.0
262  
263 10 my $self = shift;
264 10 my $route = shift;
265  
266 10 push @{$self->_get_routes}, $route;
267  
268 10 ▶ if ( $route->is_reversible ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($route->is_reversible) 10 0 10
269 10 push @{$self->_get_reversible_routes->{$route->action->id}}, $route;
270 }
271  
272 10 return;
273  
274 }
275  
276 0 ▶sub _compile_routes {
Subroutine _compile_routes: not called CC=4 SCAR=30.0
277  
278 0 my $self = shift;
279  
280 0 my @compiled_routes;
281 my @static_routes;
282  
283 0 for my $route ( @{$self->_get_routes} ) {
284  
285 0 ▶ if ( $route->isa( 'GX::Route::Static' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($route->isa('GX::Route::Static')) { } 0 0 0
286 0 push @static_routes, $route;
287 }
288 else {
289 0 push @compiled_routes, $route;
290 }
291  
292 }
293  
294 0 ▶ if ( @static_routes ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@static_routes) 0 0 0
295 0 unshift @compiled_routes, GX::Route::Static::Compiled->new( reverse @static_routes );
296 }
297  
298 0 return \@compiled_routes;
299  
300 }
301  
302 0 ▶sub _create_route {
Subroutine _create_route: not called CC=19 SCAR=59.4
303  
304 0 my $self = shift;
305 0 my %args = @_;
306  
307 0 my $action;
308  
309 0 ▶ if ( exists $args{'action'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"action"}) 0 0 0
310  
311 0 ▶ if ( exists $args{'controller'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'controller'}) { } 0 0 0
312  
313 0 ▶ if ( $self->application ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->application) 0 0 0
314 0 $action = $self->application->action( delete $args{'controller'}, delete $args{'action'} );
315 }
316  
317 }
318 else {
319  
320 0 ▶ if ( ref $args{'action'} eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $args{'action'} eq 'ARRAY') { } 0 0 0
elsif (builtin::blessed($args{'action'}) and $args{'action'}->isa('GX::Action')) { } 0 0 0
321  
322 0 ▶ if ( $self->application ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->application) 0 0 0
323 0 $action = $self->application->action( @{ delete $args{'action'} } );
324 }
325  
326 }
327 ▶ elsif ( blessed $args{'action'} && $args{'action'}->isa( 'GX::Action' ) ) {
Condition0%0/3
builtin::blessed($args{"action"}) and $args{"action"}->isa("GX::Action")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($args{"action"}) and $args{"action"}->isa("GX::Action")
builtin::blessed($args{"action"}) $args{"action"}->isa("GX::Action")
Truth table0%0/3
A and B
A= builtin::blessed($args{"action"})B= $args{"action"}->isa("GX::Action")
ABresult
0X0
100
111
328 0 $action = delete $args{'action'};
329 }
330  
331 }
332  
333 }
334  
335 0 ▶ if ( ! $action ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action) 0 0 0
336 0 complain "Unknown action";
337 }
338  
339 0 my $route_class;
340  
341 0 ▶ if ( exists $args{'class'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'class'}) { } 0 0 0
342  
343 0 ▶ if ( ! defined $args{'class'} || $args{'class'} !~ REGEX_CLASS_NAME ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (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
344 0 complain "Invalid argument (\"class\")";
345 }
346  
347 0 $route_class = delete $args{'class'};
348  
349 }
350 else {
351  
352 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
353 ( defined $args{'path'} && $args{'path'} =~ /[*{}]+/ ) ||
354 ( defined $args{'host'} && $args{'host'} =~ /[*{}]+/ ) ||
355 exists $args{'methods'} ||
356 exists $args{'schemes'}
357 ) {
358 0 $route_class = 'GX::Route::Dynamic';
359 }
360 else {
361 0 $route_class = 'GX::Route::Static';
362 }
363  
364 }
365  
366 0 my $route = eval {
367 0 $route_class->new( %args, action => $action );
368 };
369  
370 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
371 0 complain $@;
372 }
373  
374 0 return $route;
375  
376 }
377  
378 0 ▶sub _deploy {
Subroutine _deploy: not called CC=1 SCAR=6.9
379  
380 0 my $self = shift;
381  
382 0 $self->_deploy_default_action;
383 0 $self->_deploy_routes;
384  
385 0 return;
386  
387 }
388  
389 0 ▶sub _deploy_default_action {
Subroutine _deploy_default_action: not called CC=4 SCAR=30.0
390  
391 0 my $self = shift;
392  
393 0 ▶ if ( my $action = $self->_get_config->{'default_action'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $action = $self->_get_config->{"default_action"}) 0 0 0
394  
395 0 ▶ if ( ref $action eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $action eq "ARRAY") 0 0 0
396  
397 0 $action = $self->application->action( @$action );
398  
399 0 ▶ if ( ! $action ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action) 0 0 0
400 0 throw "Unknown default action";
401 }
402  
403 }
404  
405 0 $self->_set_default_action( $action );
406  
407 }
408  
409 0 return;
410  
411 }
412  
413 0 ▶sub _deploy_routes {
Subroutine _deploy_routes: not called CC=9 SCAR=45.0
414  
415 0 my $self = shift;
416  
417 0 ▶ if ( $self->_get_config->{'routes'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_get_config->{"routes"}) 0 0 0
418  
419 0 for my $route ( @{$self->_get_config->{'routes'}} ) {
420  
421 0 ▶ if ( ref $route eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $route eq 'HASH') { } 0 0 0
elsif (builtin::blessed($route) and $route->isa('GX::Route')) { } 0 0 0
422  
423 0 $route = eval {
424 0 $self->_create_route( %$route );
425 };
426  
427 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
428 0 GX::Exception->throw(
429 message => "Cannot create route",
430 subexception => $@
431 );
432 }
433  
434 0 $self->_add_route( $route );
435  
436 }
437 ▶ elsif ( blessed $route && $route->isa( 'GX::Route' ) ) {
Condition0%0/3
builtin::blessed($route) and $route->isa("GX::Route")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($route) and $route->isa("GX::Route")
builtin::blessed($route) $route->isa("GX::Route")
Truth table0%0/3
A and B
A= builtin::blessed($route)B= $route->isa("GX::Route")
ABresult
0X0
100
111
438 0 $self->_add_route( $route );
439 }
440 else {
441 0 throw "Invalid route definition";
442 }
443  
444 }
445  
446 }
447  
448 0 for my $controller ( $self->application->controllers ) {
449  
450 0 for my $route ( $controller->routes ) {
451 0 $self->_add_route( $route );
452 }
453  
454 }
455  
456 0 $self->_clear_compiled_routes;
457  
458 0 return;
459  
460 }
461  
462 10 ▶sub _remove_route {
Subroutine _remove_route: called CC=4 SCAR=14.0
463  
464 10 my $self = shift;
465 10 my $route = shift;
466  
467 10 my $routes = $self->_get_routes;
468 10 my $routes_count = @$routes;
469  
470 10 @$routes = grep { $_ != $route } @$routes;
471  
472 10 ▶ $routes_count - @$routes or return;
Branch: 1 branch
BranchTrueFalseTotal
$routes_count - @$routes or return 10 0 10
473  
474 10 ▶ if ( $route->is_reversible ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($route->is_reversible) 10 0 10
475  
476 10 my $reversible_routes = $self->_get_reversible_routes->{$route->action->id};
477  
478 10 @$reversible_routes = grep { $_ != $route } @$reversible_routes;
479  
480 10 ▶ if ( ! @$reversible_routes ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$reversible_routes) 10 0 10
481 10 delete $self->_get_reversible_routes->{$route->action->id};
482 }
483  
484 }
485  
486 10 return 1;
487  
488 }
489  
490 40 ▶sub _reversible_route_for_action {
Subroutine _reversible_route_for_action: called CC=2 SCAR=6.9
491  
492 40 my $self = shift;
493 40 my $action = shift;
494  
495 40 ▶ return ( $self->_get_reversible_routes->{$action->id} || return undef )->[0];
Condition100%2/2
$self->_get_reversible_routes->{$action->id} || (return undef)
l!l
2020
MC/DC100%1/1
$self->_get_reversible_routes->{$action->id} || (return undef)
$self->_get_reversible_routes->{$action->id}
Truth table100%2/2
A
A= $self->_get_reversible_routes->{$action->id}
Aresult
11
00
496  
497 }
498  
499 1 ▶sub _setup_config {
Subroutine _setup_config: called CC=9 SCAR=38.1
500  
501 1 my $self = shift;
502 1 my $args = shift;
503  
504 1 my $config = $self->_get_config;
505  
506 1 ▶ if ( exists $args->{'default_action'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"default_action"}) 0 1 1
507  
508 0 my $action = delete $args->{'default_action'};
509  
510 0 ▶ if ( defined $action ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $action) 0 0 0
511  
512 0 ▶ if ( ref $action eq 'ARRAY' || ( blessed $action && $action->isa( 'GX::Action' ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $action eq 'ARRAY' or builtin::blessed($action) and $action->isa('GX::Action')) { } 0 0 0
Condition0%0/6
ref $action eq "ARRAY" or builtin::blessed($action) and $action->isa("GX::Action")
l!l&&r!l&&!r
000
builtin::blessed($action) and $action->isa("GX::Action")
!ll&&!rl&&r
000
MC/DC0%0/3
ref $action eq "ARRAY" or builtin::blessed($action) and $action->isa("GX::Action")
ref $action eq "ARRAY" builtin::blessed($action) $action->isa("GX::Action")
Truth table0%0/4
A or B and C
A= ref $action eq "ARRAY"B= builtin::blessed($action)C= $action->isa("GX::Action")
ABCresult
1XX1
0111
00X0
0100
513 0 $config->{'default_action'} = $action;
514 }
515 else {
516 0 throw "Invalid option (\"default_action\" must be an array reference or a GX::Action object)";
517 }
518  
519 }
520  
521 }
522  
523 1 ▶ if ( exists $args->{'routes'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"routes"}) 0 1 1
524  
525 0 my $routes = delete $args->{'routes'};
526  
527 0 ▶ if ( defined $routes ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $routes) 0 0 0
528  
529 0 ▶ if ( ref $routes eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $routes eq 'ARRAY') { } 0 0 0
530 0 $config->{'routes'} = $routes;
531 }
532 else {
533 0 throw "Invalid option (\"routes\" must be an array reference)";
534 }
535  
536 }
537  
538 }
539  
540 1 return;
541  
542 }
543  
544 0 ▶sub _start {
Subroutine _start: not called CC=1 SCAR=6.9
545  
546 0 my $self = shift;
547  
548 0 $self->SUPER::_start;
549  
550 0 $self->_set_compiled_routes( $self->_compile_routes );
551  
552 0 return;
553  
554 }
555  
556 1 ▶sub _validate_class_name {
Subroutine _validate_class_name: called CC=1 SCAR=0.0
557  
558 1 return $_[1] =~ /^(?:[_a-zA-Z]\w*::)+?Router$/;
559  
560 }
561  
562  
563 2 1;
564  
565 __END__
« GX/SQL/Builder.pm ↑ Summary GX/Session.pm »