GX/Route/Static.pm

filter: Statementstmt 96.3% 52 / 54 Branchbran 81.2% 26 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 92.1% 94 / 102 CC 17 SCAR 15.0
CC
17
Cov
91%
match
9.0
construct_uri
5.0
__ANON__
2.1
CRAP 4.5
« GX/HTTP/Parser/Body.pm ↑ Summary GX/Meta/Attribute/Scalar.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Route/Static.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Route::Static;
7  
8 23 ▶use GX::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 # ----------------------------------------------------------------------------------------------------------------------
12 # Class setup
13 # ----------------------------------------------------------------------------------------------------------------------
14  
15 23 ▶use GX::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 23 extends 'GX::Route';
18  
19 has 'action' => (
20 isa => 'Object',
21 required => 1,
22 67 ▶ constraint => sub { $_->isa( 'GX::Action' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
23 23 accessor => { type => 'get' }
24 );
25  
26 has 'host' => (
27 isa => 'Scalar',
28 initialize => 1,
29 19 ▶ constraint => sub { defined && length },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ 19 0 19
30 23 accessor => { type => 'get' }
31 );
32  
33 23 has 'is_reversible' => (
34 isa => 'Bool',
35 initialize => 1,
36 default => 1,
37 accessor => { type => 'get' }
38 );
39  
40 has 'method' => (
41 isa => 'Scalar',
42 initialize => 1,
43 13 ▶ constraint => sub { defined && length },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ 13 0 13
44 13 ▶ processor => sub { $_ = uc },
Subroutine __ANON__: called CC=1 SCAR=0.0
45 23 accessor => { type => 'get' }
46 );
47  
48 has 'path' => (
49 isa => 'String',
50 required => 1,
51 67 ▶ constraint => sub { /^\// },
Subroutine __ANON__: called CC=1 SCAR=0.0
52 23 accessor => { type => 'get' }
53 );
54  
55 has 'scheme' => (
56 isa => 'Scalar',
57 initialize => 1,
58 13 ▶ constraint => sub { defined && length },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ 13 0 13
59 13 ▶ processor => sub { $_ = lc },
Subroutine __ANON__: called CC=1 SCAR=0.0
60 23 accessor => { type => 'get' }
61 );
62  
63 23 build;
64  
65  
66 # ----------------------------------------------------------------------------------------------------------------------
67 # Public methods
68 # ----------------------------------------------------------------------------------------------------------------------
69  
70 11 ▶sub construct_path {
Subroutine construct_path: called CC=2 SCAR=7.6
Pod documented
71  
72 11 my $self = shift;
73  
74 11 ▶ if ( ! $self->{'is_reversible'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"is_reversible"}) 0 11 11
75 0 complain "Route is not reversible";
76 }
77  
78 11 return $self->{'path'};
79  
80 }
81  
82 24 ▶sub construct_uri {
Subroutine construct_uri: called CC=5 SCAR=16.1
Pod documented
83  
84 24 my $self = shift;
85 24 my %args = @_;
86  
87 24 ▶ if ( ! $self->{'is_reversible'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"is_reversible"}) 0 24 24
88 0 complain "Route is not reversible";
89 }
90  
91 24 ▶ if ( defined $self->{'scheme'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"scheme"}) 2 22 24
92 2 $args{'scheme'} = $self->{'scheme'};
93 }
94  
95 24 ▶ if ( defined $self->{'host'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"host"}) 4 20 24
96 4 $args{'host'} = $self->{'host'};
97 }
98  
99 24 $args{'path'} = $self->{'path'};
100  
101 24 my $uri = eval { $self->_construct_uri( %args ) };
102  
103 24 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 23 24
104 1 complain $@;
105 }
106  
107 23 return $uri;
108  
109 }
110  
111 25 ▶sub match {
Subroutine match: called CC=9 SCAR=22.0
Pod documented
112  
113 25 my $self = shift;
114 25 my $context = shift;
115  
116 25 ▶ my $request = $context->request or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $request = $context->request or return undef 25 0 25
117  
118 23 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
119  
120 25 ▶ if ( defined $self->{'method'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"method"}) 4 21 25
121 4 ▶ return undef if $request->method ne $self->{'method'};
Branch: 1 branch
BranchTrueFalseTotal
if $request->method ne $self->{"method"} 3 1 4
122 }
123  
124 22 ▶ if ( defined $self->{'scheme'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"scheme"}) 4 18 22
125 4 ▶ return undef if $request->scheme ne $self->{'scheme'};
Branch: 1 branch
BranchTrueFalseTotal
if $request->scheme ne $self->{"scheme"} 3 1 4
126 }
127  
128 19 ▶ if ( defined $self->{'host'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"host"}) 4 15 19
129 4 ▶ return undef if $request->host ne $self->{'host'};
Branch: 1 branch
BranchTrueFalseTotal
if $request->host ne $self->{"host"} 3 1 4
130 }
131  
132 16 ▶ return undef if $request->path ne $self->{'path'};
Branch: 1 branch
BranchTrueFalseTotal
if $request->path ne $self->{"path"} 10 6 16
133  
134 6 return GX::Route::Match->new( action => $self->{'action'} );
135  
136 }
137  
138  
139 23 1;
140  
141 __END__
« GX/HTTP/Parser/Body.pm ↑ Summary GX/Meta/Attribute/Scalar.pm »