| 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($@)
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($@)
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 7 | for my $route ( @routes ) { | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 39 | ▶ | if ( blessed $route && $route->isa( 'GX::Route::Static' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($route) and $route->isa("GX::Route::Static")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Caution: Avoid auto-vivification! | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 74 | my @scheme_nodes; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 74 | ▶ | if ( defined $scheme ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 72 | ▶ | if ( exists $self->{'routes'}{$scheme} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 20 | push @scheme_nodes, $self->{'routes'}{$scheme}; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 74 | ▶ | if ( exists $self->{'routes'}{''} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 74 | ▶ | if ( exists $scheme_node->{$host} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 25 | push @host_nodes, $scheme_node->{$host}; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 76 | ▶ | if ( exists $scheme_node->{''} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 57 | ▶ | if ( defined $method ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 56 | ▶ | if ( my $action = $path_node->{$method} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 19 | return GX::Route::Match->new( action => $action ); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 38 | ▶ | if ( my $action = $path_node->{''} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||