SPORE/Request.pm

filter: Statementstmt 20.4% 17 / 83 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 26.3% 5 / 19 Podpod 100% 14 / 14 totaltotal 25.0% 36 / 144 CC 16 SCAR 21.5
CC
16
Cov
15%
as_request
30.0
request_method
6.0
script_name
6.0
CRAP 8.6
« SPORE/Loader.pm ↑ Summary SPORE/Definition.pm »
1 package Net::Async::SPORE::Request;
2 3 $Net::Async::SPORE::Request::VERSION = '0.003';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Net::Async::SPORE::Definition - holds information about a SPORE definition
9  
10 =head1 VERSION
11  
12 Version 0.003
13  
14 =head1 DESCRIPTION
15  
16 =cut
17  
18 3 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use URI::QueryParam;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use URI::Escape qw(uri_escape_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 =head1 METHODS
23  
24 =cut
25  
26 =head2 new
27  
28 Instantiate this request. Any named parameters will be
29 used to populate the environment.
30  
31 =cut
32  
33 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
34 0 my $class = shift;
35 0 bless { env => { @_ } }, $class
36 }
37  
38 =head2 env
39  
40 Returns the environment hashref.
41  
42 =cut
43  
44 0 ▶sub env { shift->{env} }
Subroutine env: not called CC=1 SCAR=6.9
Pod documented
45  
46 =head2 as_request
47  
48 Returns an L<HTTP::Request> object representing this
49 environment.
50  
51 =cut
52  
53 0 ▶sub as_request {
Subroutine as_request: not called CC=5 SCAR=34.0
Pod documented
54 0 my ($self) = @_;
55  
56 0 require HTTP::Request;
57 0 my $uri = URI->new(
58 $self->scheme . '://' . $self->server_name
59 );
60  
61 0 my $path = $self->request_uri;
62  
63 # Apply our parameters
64 0 my @param = @{$self->params};
65 0 ▶ while(my ($k, $v) = splice @param, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@param, 0, 2)) 0 0 0
66 0 ▶ unless($path =~ s/:$k/uri_escape_utf8($v)/ge) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ s/:$k/uri_escape_utf8($v);/eg) 0 0 0
67 0 $uri->query_param_append($k => $v);
68 }
69 }
70  
71 0 $uri->path($path);
72  
73 # Convert this into a request
74 0 my $req = HTTP::Request->new(
75 $self->request_method => $uri
76 );
77 0 $req->protocol('HTTP/1.1');
78 0 ▶ $req->content($self->payload) if length $self->payload;
Branch: 1 branch
BranchTrueFalseTotal
if length $self->payload 0 0 0
79  
80 0 my $env = $self->env;
81 0 for my $k (grep /^HTTPS?_/, keys %$env) {
82 0 my ($name) = $k =~ /^HTTPS?_(.*)/;
83 0 $req->header($name => $env->{$k});
84 }
85 0 return $req;
86 }
87  
88 =head1 METHODS - Environment accessors
89  
90 These provide accessor/mutator support for the environment entries.
91  
92 =head2 request_method
93  
94 =cut
95  
96 0 ▶sub request_method {
Subroutine request_method: not called CC=2 SCAR=17.9
Pod documented
97 0 my ($self) = shift;
98 0 ▶ return $self->env->{REQUEST_METHOD} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
99 0 $self->env->{REQUEST_METHOD} = shift;
100 0 return $self;
101 }
102  
103 =head2 script_name
104  
105 =cut
106  
107 0 ▶sub script_name {
Subroutine script_name: not called CC=2 SCAR=17.9
Pod documented
108 0 my ($self) = shift;
109 0 ▶ return $self->env->{SCRIPT_NAME} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
110 0 $self->env->{SCRIPT_NAME} = shift;
111 0 return $self;
112 }
113  
114 =head2 path_info
115  
116 =cut
117  
118 0 ▶sub path_info {
Subroutine path_info: not called CC=2 SCAR=17.9
Pod documented
119 0 my ($self) = shift;
120 0 ▶ return $self->env->{PATH_INFO} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
121 0 $self->env->{PATH_INFO} = shift;
122 0 return $self;
123 }
124  
125 =head2 request_uri
126  
127 =cut
128  
129 0 ▶sub request_uri {
Subroutine request_uri: not called CC=2 SCAR=17.9
Pod documented
130 0 my ($self) = shift;
131 0 ▶ return $self->env->{REQUEST_URI} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
132 0 $self->env->{REQUEST_URI} = shift;
133 0 return $self;
134 }
135  
136 =head2 server_name
137  
138 =cut
139  
140 0 ▶sub server_name {
Subroutine server_name: not called CC=2 SCAR=17.9
Pod documented
141 0 my ($self) = shift;
142 0 ▶ return $self->env->{SERVER_NAME} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
143 0 $self->env->{SERVER_NAME} = shift;
144 0 return $self;
145 }
146  
147 =head2 server_port
148  
149 =cut
150  
151 0 ▶sub server_port {
Subroutine server_port: not called CC=2 SCAR=17.9
Pod documented
152 0 my ($self) = shift;
153 0 ▶ return $self->env->{SERVER_PORT} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
154 0 $self->env->{SERVER_PORT} = shift;
155 0 return $self;
156 }
157  
158 =head2 query_string
159  
160 =cut
161  
162 0 ▶sub query_string {
Subroutine query_string: not called CC=2 SCAR=17.9
Pod documented
163 0 my ($self) = shift;
164 0 ▶ return $self->env->{QUERY_STRING} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
165 0 $self->env->{QUERY_STRING} = shift;
166 0 return $self;
167 }
168  
169 =head2 payload
170  
171 =cut
172  
173 0 ▶sub payload {
Subroutine payload: not called CC=2 SCAR=17.9
Pod documented
174 0 my ($self) = shift;
175 0 ▶ return $self->env->{payload} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
176 0 $self->env->{payload} = shift;
177 0 return $self;
178 }
179  
180 =head2 params
181  
182 =cut
183  
184 0 ▶sub params {
Subroutine params: not called CC=2 SCAR=17.9
Pod documented
185 0 my ($self) = shift;
186 0 ▶ return $self->env->{params} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
187 0 $self->env->{params} = shift;
188 0 return $self;
189 }
190  
191 =head2 redirections
192  
193 =cut
194  
195 0 ▶sub redirections {
Subroutine redirections: not called CC=2 SCAR=17.9
Pod documented
196 0 my ($self) = shift;
197 0 ▶ return $self->env->{redirections} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
198 0 $self->env->{redirections} = shift;
199 0 return $self;
200 }
201  
202 =head2 scheme
203  
204 =cut
205  
206 0 ▶sub scheme {
Subroutine scheme: not called CC=2 SCAR=17.9
Pod documented
207 0 my ($self) = shift;
208 0 ▶ return $self->env->{scheme} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
209 0 $self->env->{scheme} = shift;
210 0 return $self;
211 }
212  
213 3 1;
214  
215 __END__
« SPORE/Loader.pm ↑ Summary SPORE/Definition.pm »