GX/Request.pm

filter: Statementstmt 86.9% 73 / 84 Branchbran 35.0% 7 / 20 Conditioncond 75.0% 6 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 76.0% 19 / 25 Podpod 100% 8 / 8 totaltotal 76.0% 114 / 150 CC 14 SCAR 11.8
CC
14
Cov
77%
has_body
6.0
has_cookies
6.0
has_headers
6.0
CRAP 3.3
« GX/Logger.pm ↑ Summary GX/HTML/Util.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Request.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Request;
7  
8 9 ▶use GX::HTTP::Parameters;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use GX::HTTP::Parser::Body;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use GX::HTTP::Request::Cookie;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use GX::HTTP::Request::Cookies;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use GX::HTTP::Uploads;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 9 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 # ----------------------------------------------------------------------------------------------------------------------
18 # Class setup
19 # ----------------------------------------------------------------------------------------------------------------------
20  
21 9 ▶use GX::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 9 extends qw( GX::Component GX::HTTP::Request );
24  
25 9 has 'body_parameters' => (
26 isa => 'Scalar',
27 initializer => '_initialize_body_parameters'
28 );
29  
30 9 has 'body_parser' => (
31 isa => 'Scalar',
32 initializer => '_initialize_body_parser'
33 );
34  
35 9 has 'cookies' => (
36 isa => 'Scalar',
37 initializer => '_initialize_cookies'
38 );
39  
40 9 has 'format' => (
41 isa => 'Scalar'
42 );
43  
44 9 has 'host' => (
45 isa => 'Scalar'
46 );
47  
48 9 has 'parameters' => (
49 isa => 'Scalar',
50 initializer => '_initialize_parameters'
51 );
52  
53 9 has 'parsed_body' => (
54 isa => 'Scalar',
55 accessors => {
56 '_get_parsed_body' => { type => 'get' },
57 '_set_parsed_body' => { type => 'set' }
58 }
59 );
60  
61 9 has 'path' => (
62 isa => 'Scalar'
63 );
64  
65 9 has 'path_parameters' => (
66 isa => 'Scalar',
67 initializer => '_initialize_path_parameters'
68 );
69  
70 9 has 'port' => (
71 isa => 'Scalar'
72 );
73  
74 9 has 'query' => (
75 isa => 'Scalar'
76 );
77  
78 9 has 'query_parameters' => (
79 isa => 'Scalar',
80 initializer => '_initialize_query_parameters'
81 );
82  
83 9 has 'read_callback' => (
84 isa => 'Scalar'
85 );
86  
87 9 has 'remote_address' => (
88 isa => 'Scalar'
89 );
90  
91 9 has 'scheme' => (
92 isa => 'Scalar'
93 );
94  
95 9 has 'uploads' => (
96 isa => 'Scalar',
97 initializer => '_initialize_uploads'
98 );
99  
100 9 has static 'tmp_dir' => (
101 isa => 'Scalar',
102 accessors => {
103 '_get_tmp_dir' => { type => 'get' },
104 '_set_tmp_dir' => { type => 'set' }
105 }
106 );
107  
108 9 build;
109  
110  
111 # ----------------------------------------------------------------------------------------------------------------------
112 # Export mechanism
113 # ----------------------------------------------------------------------------------------------------------------------
114  
115 9 __PACKAGE__->_install_import_method;
116  
117  
118 # ----------------------------------------------------------------------------------------------------------------------
119 # Public methods
120 # ----------------------------------------------------------------------------------------------------------------------
121  
122 4 ▶sub cookie {
Subroutine cookie: called CC=1 SCAR=0.0
Pod documented
123  
124 4 return shift->cookies->get( @_ );
125  
126 }
127  
128 0 ▶sub has_body {
Subroutine has_body: not called CC=2 SCAR=17.9
Pod documented
129  
130 0 ▶ return $_[0]->body->length ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->body->length ? : 0 0 0
131  
132 }
133  
134 0 ▶sub has_cookies {
Subroutine has_cookies: not called CC=2 SCAR=17.9
Pod documented
135  
136 0 ▶ return $_[0]->cookies->count ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->cookies->count ? : 0 0 0
137  
138 }
139  
140 0 ▶sub has_headers {
Subroutine has_headers: not called CC=2 SCAR=17.9
Pod documented
141  
142 0 ▶ return $_[0]->headers->count ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->headers->count ? : 0 0 0
143  
144 }
145  
146 0 ▶sub has_parameters {
Subroutine has_parameters: not called CC=2 SCAR=17.9
Pod documented
147  
148 0 ▶ return $_[0]->parameters->count ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->parameters->count ? : 0 0 0
149  
150 }
151  
152 0 ▶sub has_uploads {
Subroutine has_uploads: not called CC=2 SCAR=17.9
Pod documented
153  
154 0 ▶ return $_[0]->uploads->count ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->uploads->count ? : 0 0 0
155  
156 }
157  
158 10 ▶sub parameter {
Subroutine parameter: called CC=1 SCAR=0.0
Pod documented
159  
160 10 return shift->parameters->get( @_ );
161  
162 }
163  
164 4 ▶sub upload {
Subroutine upload: called CC=1 SCAR=0.0
Pod documented
165  
166 4 return shift->uploads->get( @_ );
167  
168 }
169  
170  
171 # ----------------------------------------------------------------------------------------------------------------------
172 # Private methods
173 # ----------------------------------------------------------------------------------------------------------------------
174  
175 7 ▶sub _initialize_body_parameters {
Subroutine _initialize_body_parameters: called CC=2 SCAR=7.2
176  
177 7 ▶ return $_[0]->_parse_body->{'parameters'} // GX::HTTP::Parameters->new;
Condition66%2/3
$_[0]->_parse_body->{"parameters"} // "GX::HTTP::Parameters"->new
l!l&&r!l&&!r
250
MC/DC0%0/2
$_[0]->_parse_body->{"parameters"} // "GX::HTTP::Parameters"->new
$_[0]->_parse_body->{"parameters"} "GX::HTTP::Parameters"->new
Truth table66%2/3
A // B
A= $_[0]->_parse_body->{"parameters"}B= "GX::HTTP::Parameters"->new
ABresult
1X1
011
000
178  
179 }
180  
181 4 ▶sub _initialize_body_parser {
Subroutine _initialize_body_parser: called CC=2 SCAR=6.9
182  
183 4 my $self = shift;
184  
185 4 my $content_type = $self->content_type;
186  
187 4 ▶ if ( ! defined $content_type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content_type) 1 3 4
188 1 return undef;
189 }
190  
191 3 return GX::HTTP::Parser::Body->new(
192 content_type => $content_type,
193 tmp_dir => $self->_get_tmp_dir
194 );
195  
196 }
197  
198 4 ▶sub _initialize_cookies {
Subroutine _initialize_cookies: called CC=1 SCAR=0.0
199  
200 4 my $self = shift;
201  
202 4 my $cookies = GX::HTTP::Request::Cookies->new;
203  
204 4 $cookies->add( map { GX::HTTP::Request::Cookie->parse( $_ ) } $self->headers->cookie );
205  
206 4 return $cookies;
207  
208 }
209  
210 7 ▶sub _initialize_parameters {
Subroutine _initialize_parameters: called CC=1 SCAR=0.0
211  
212 7 my $self = shift;
213  
214 7 return GX::HTTP::Parameters->merge(
215 $self->path_parameters,
216 $self->query_parameters,
217 $self->body_parameters
218 );
219  
220 }
221  
222 5 ▶sub _initialize_path_parameters {
Subroutine _initialize_path_parameters: called CC=1 SCAR=0.0
223  
224 5 return GX::HTTP::Parameters->new;
225  
226 }
227  
228 7 ▶sub _initialize_query_parameters {
Subroutine _initialize_query_parameters: called CC=1 SCAR=0.0
229  
230 7 return GX::HTTP::Parameters->parse( $_[0]->query );
231  
232 }
233  
234 3 ▶sub _initialize_uploads {
Subroutine _initialize_uploads: called CC=2 SCAR=7.2
235  
236 3 ▶ return $_[0]->_parse_body->{'uploads'} // GX::HTTP::Uploads->new;
Condition66%2/3
$_[0]->_parse_body->{"uploads"} // "GX::HTTP::Uploads"->new
l!l&&r!l&&!r
120
MC/DC0%0/2
$_[0]->_parse_body->{"uploads"} // "GX::HTTP::Uploads"->new
$_[0]->_parse_body->{"uploads"} "GX::HTTP::Uploads"->new
Truth table66%2/3
A // B
A= $_[0]->_parse_body->{"uploads"}B= "GX::HTTP::Uploads"->new
ABresult
1X1
011
000
237  
238 }
239  
240 10 ▶sub _parse_body {
Subroutine _parse_body: called CC=5 SCAR=16.1
241  
242 10 my $self = shift;
243  
244 10 my $parsed_body = $self->_get_parsed_body;
245  
246 10 ▶ if ( ! $parsed_body ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parsed_body) 9 1 10
247  
248 9 my $body = $self->body;
249  
250 9 ▶ if ( $body->length > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body->length > 0) 3 6 9
251  
252 3 my $parser = $self->body_parser;
253  
254 3 ▶ if ( $parser ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser) 3 0 3
255 3 $parsed_body = $parser->parse( $body );
256 }
257  
258 }
259  
260 9 ▶ $parsed_body //= {};
Condition100%2/2
$parsed_body //= {}
l!l
36
MC/DC100%1/1
$parsed_body //= {}
$parsed_body
Truth table100%2/2
A
A= $parsed_body
Aresult
11
00
261  
262 9 $self->_set_parsed_body( $parsed_body );
263  
264 }
265  
266 10 return $parsed_body;
267  
268 }
269  
270 0 ▶sub _register {
Subroutine _register: not called CC=2 SCAR=17.9
271  
272 0 my $class = shift;
273 0 my $application = shift;
274  
275 0 $class->SUPER::_register( $application );
276  
277 0 ▶ if ( ! defined $class->_get_tmp_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $class->_get_tmp_dir) 0 0 0
278 0 $class->_set_tmp_dir( $application->path( 'tmp' ) );
279 }
280  
281 0 return;
282  
283 }
284  
285 7 ▶sub _validate_class_name {
Subroutine _validate_class_name: called CC=1 SCAR=0.0
286  
287 7 return $_[1] =~ /^(?:[_a-zA-Z]\w*::)+Request$/;
288  
289 }
290  
291  
292 9 1;
293  
294 __END__
« GX/Logger.pm ↑ Summary GX/HTML/Util.pm »