GX/Route/Static/Compiled.pm

filter: Statementstmt 98.2% 56 / 57 Branchbran 88.4% 23 / 26 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 88.2% 90 / 102 CC 19 SCAR 23.4
CC
19
Cov
91%
match
15.0
new
6.1
BEGIN
1.0
CRAP 10.4
« GX/HTTP/Request/Cookie.pm ↑ Summary GX/Class.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Route/Static/Compiled.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Route::Static::Compiled;
7  
8 4 ▶use GX::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 # ----------------------------------------------------------------------------------------------------------------------
14 # Class setup
15 # ----------------------------------------------------------------------------------------------------------------------
16  
17 4 ▶use GX::Class::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 has 'routes' => (
20 isa => 'Hash',
21 initialize => 1,
22 accessor => undef
23 );
24  
25 4 build;
26  
27  
28 # ----------------------------------------------------------------------------------------------------------------------
29 # Constructor
30 # ----------------------------------------------------------------------------------------------------------------------
31  
32 7 ▶sub new {
Subroutine new: called CC=5 SCAR=18.1
Pod documented
33  
34 7 my $class = shift;
35 7 my @routes = @_;
36  
37 7 ▶ my $self = eval { $class->SUPER::new } || complain( $@ );
Condition33%1/3
eval { do { $class->SUPER::new } } || &complain($@)
l!l&&r!l&&!r
700
MC/DC0%0/2
eval { do { $class->SUPER::new } } || &complain($@)
eval { do { $class->SUPER::new } } &complain($@)
Truth table33%1/3
A || B
A= eval { do { $class->SUPER::new } }B= &complain($@)
ABresult
1X1
011
000
38  
39 7 for my $route ( @routes ) {
40
41 39 ▶ if ( blessed $route && $route->isa( 'GX::Route::Static' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($route) and $route->isa('GX::Route::Static')) { } 39 0 39
Condition33%1/3
builtin::blessed($route) and $route->isa("GX::Route::Static")
!ll&&!rl&&r
0039
MC/DC0%0/2
builtin::blessed($route) and $route->isa("GX::Route::Static")
builtin::blessed($route) $route->isa("GX::Route::Static")
Truth table33%1/3
A and B
A= builtin::blessed($route)B= $route->isa("GX::Route::Static")
ABresult
0X0
100
111
42 39 $self->_add_route( $route );
43 }
44 else {
45 0 complain "Invalid argument";
46 }
47  
48 }
49  
50 7 return $self;
51  
52 }
53  
54  
55 # ----------------------------------------------------------------------------------------------------------------------
56 # Public methods
57 # ----------------------------------------------------------------------------------------------------------------------
58  
59 75 ▶sub match {
Subroutine match: called CC=15 SCAR=27.1
Pod documented
60  
61 75 my $self = shift;
62 75 my $context = shift;
63  
64 75 ▶ my $request = $context->request or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $request = $context->request or return undef 75 0 75
65  
66 75 my $method = $request->method;
67 75 my $scheme = $request->scheme;
68 75 my $host = $request->host;
69 75 my $path = $request->path;
70  
71 75 ▶ return undef unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 1 74 75
72  
73 # Caution: Avoid auto-vivification!
74  
75 74 my @scheme_nodes;
76  
77 74 ▶ if ( defined $scheme ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $scheme) 72 2 74
78  
79 72 ▶ if ( exists $self->{'routes'}{$scheme} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"routes"}{$scheme}) 20 52 72
80 20 push @scheme_nodes, $self->{'routes'}{$scheme};
81 }
82  
83 }
84  
85 74 ▶ if ( exists $self->{'routes'}{''} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"routes"}{""}) 69 5 74
86 69 push @scheme_nodes, $self->{'routes'}{''};
87 }
88  
89 74 for my $scheme_node ( @scheme_nodes ) {
90  
91 76 my @host_nodes;
92  
93 76 ▶ if ( defined $host ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $host) 74 2 76
94  
95 74 ▶ if ( exists $scheme_node->{$host} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $scheme_node->{$host}) 25 49 74
96 25 push @host_nodes, $scheme_node->{$host};
97 }
98  
99 }
100  
101 76 ▶ if ( exists $scheme_node->{''} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $scheme_node->{""}) 71 5 76
102 71 push @host_nodes, $scheme_node->{''};
103 }
104  
105 76 for my $host_node ( @host_nodes ) {
106  
107 80 ▶ if ( my $path_node = $host_node->{$path} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path_node = $host_node->{$path}) 57 23 80
108  
109 57 ▶ if ( defined $method ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $method) 56 1 57
110  
111 56 ▶ if ( my $action = $path_node->{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $action = $path_node->{$method}) 19 37 56
112 19 return GX::Route::Match->new( action => $action );
113 }
114  
115 }
116  
117 38 ▶ if ( my $action = $path_node->{''} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $action = $path_node->{""}) 38 0 38
118 38 return GX::Route::Match->new( action => $action );
119 }
120  
121 }
122  
123 }
124  
125 }
126  
127 17 return undef;
128  
129 }
130  
131  
132 # ----------------------------------------------------------------------------------------------------------------------
133 # Private methods
134 # ----------------------------------------------------------------------------------------------------------------------
135  
136 39 ▶sub _add_route {
Subroutine _add_route: called CC=1 SCAR=0.0
137  
138 39 my $self = shift;
139 39 my $route = shift;
140  
141 4 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
142  
143 39 $self->{'routes'}{$route->scheme}{$route->host}{$route->path}{$route->method} = $route->action;
144  
145 39 return;
146  
147 }
148  
149  
150 4 1;
151  
152 __END__
« GX/HTTP/Request/Cookie.pm ↑ Summary GX/Class.pm »