lib/Drogo/Server/Test.pm

filter: Statementstmt 65.9% 31 / 47 Branchbran 50.0% 3 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 50.0% 12 / 24 Podpod 85.7% 18 / 21 totaltotal 63.3% 64 / 101 CC 5 SCAR 7.7
CC
5
Cov
62%
request_method
6.0
remote_addr
6.0
status
2.1
CRAP 2.2
« lib/Drogo/Server.pm ↑ Summary blib/lib/Drogo.pm »
1 package Drogo::Server::Test;
2 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use base 'Drogo::Server';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 my %SERVER_VARIABLES;
8  
9 =head1 NAME
10  
11 Drogo::Server::Test - Bare implementation of a server's methods, for testing.
12  
13 =head1 METHODS
14  
15 =head3 new
16  
17 Create a new server instance.
18  
19 =cut
20  
21 sub new
22 16 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
23 16 my ($class, %params) = @_;
24 16 %SERVER_VARIABLES = ( );
25 16 my $self = { %params, output => '' };
26  
27 16 bless($self);
28  
29 16 return $self;
30 }
31  
32 =head3 variable(key => $value)
33  
34 Returns a persistant server variable.
35  
36 Key without value returns variable.
37  
38 These include variables set by the server configuration, as "user variables" in nginx.
39  
40 =cut
41  
42 sub variable
43 120 ▶{
Subroutine variable: called CC=2 SCAR=6.9
Pod documented
44 120 my ($self, $key, $value) = @_;
45  
46 120 ▶ if ($value)
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 89 31 120
47 {
48 89 $SERVER_VARIABLES{$key} = $value;
49 }
50 else
51 {
52 31 return $SERVER_VARIABLES{$key};
53 }
54 }
55  
56 =head3 uri
57  
58 Returns the uri.
59  
60 =cut
61  
62 0 ▶sub uri { shift->{uri} }
Subroutine uri: not called CC=1 SCAR=6.9
Pod documented
63  
64 =head3 args
65  
66 Returns string of arguments.
67  
68 =cut
69  
70 15 ▶sub args { shift->{args} }
Subroutine args: called CC=1 SCAR=0.0
Pod documented
71  
72 =head3 request_body
73  
74 Returns the request body (used for posts)
75  
76 =cut
77  
78 15 ▶sub request_body { '' }
Subroutine request_body: called CC=1 SCAR=0.0
Pod documented
79  
80 =head3 input
81  
82 Returns input stream.
83  
84 =cut
85  
86 0 ▶sub input { }
Subroutine input: not called CC=1 SCAR=0.0
Pod documented
87  
88 =head3 request_method
89  
90 Returns the request method (GET or POST)
91  
92 =cut
93  
94 0 ▶sub request_method { shift->{request_method} || 'GET' }
Subroutine request_method: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"request_method"} or "GET" 0 0 0
95  
96 =head3 remote_addr
97  
98 Returns remote address.
99  
100 =cut
101  
102 sub remote_addr
103 0 ▶{
Subroutine remote_addr: not called CC=2 SCAR=17.9
Pod documented
104 0 my $self = shift;
105  
106 0 ▶ return $self->{remote_addr} || '127.0.0.1';
Condition0%0/2
$self->{'remote_addr'} || '127.0.0.1'
l!l
00
MC/DC0%0/1
$self->{'remote_addr'} || '127.0.0.1'
$self->{'remote_addr'}
Truth table0%0/2
A
A= $self->{'remote_addr'}
Aresult
11
00
107 }
108  
109 =head3 has_request_body
110  
111 Used by nginx for request body processing.
112  
113 This function is only called when the request method is a post,
114 in an effort to reduce processing time.
115  
116 =cut
117  
118 0 ▶sub has_request_body { }
Subroutine has_request_body: not called CC=1 SCAR=0.0
Pod documented
119  
120 =head3 header_in
121  
122 Returns a request header.
123  
124 =cut
125  
126 sub header_in
127 0 ▶{
Subroutine header_in: not called CC=1 SCAR=6.9
Pod documented
128 0 my ($self, $what) = @_;
129  
130 0 return $self->{headers_in}{$what};
131 }
132  
133 =head3 header_out
134  
135 Sets a header out.
136  
137 =cut
138  
139 sub header_out
140 0 ▶{
Subroutine header_out: not called CC=1 SCAR=6.9
Pod documented
141 0 my ($self, $header, $value) = @_;
142  
143 0 return $self->{headers_out}{$header} = $value;
144 }
145  
146 =head3 send_http_header
147  
148 Send the http header.
149  
150 =cut
151  
152 sub send_http_header
153 15 ▶{
Subroutine send_http_header: called CC=1 SCAR=0.0
Pod documented
154 15 my ($self, $header) = @_;
155  
156 15 $self->{http_header} = $header;
157 }
158  
159 =head3 $self->status(...)
160  
161 Set output status... (200, 404, etc...)
162 If no argument given, returns status.
163  
164 =cut
165  
166 sub status
167 15 ▶{
Subroutine status: called CC=2 SCAR=7.6
Pod documented
168 15 my ($self, $status) = @_;
169  
170 15 ▶ if ($status)
Branch: 1 branch
BranchTrueFalseTotal
if ($status) { } 15 0 15
171 {
172 15 $self->{status} = $status;
173 }
174 else
175 {
176 0 return $self->{status};
177 }
178 }
179  
180 =head3 print
181  
182 Print stuff to the http stream.
183  
184 =cut
185  
186 11 ▶sub print {
Subroutine print: called CC=1 SCAR=0.0
Pod documented
187 11 my ($self, $line) = @_;
188  
189 11 $self->{output} .= $line;
190 }
191  
192 15 ▶sub rflush { }
Subroutine rflush: called CC=1 SCAR=0.0
Pod undocumented
193  
194 =head3 sleep
195  
196 Sleeps (used by nginx), not needed for other server implementations.
197  
198 =cut
199  
200 sub sleep
201 0 ▶{
Subroutine sleep: not called CC=1 SCAR=6.9
Pod documented
202 0 my $self = shift;
203 0 sleep(shift);
204 }
205  
206 =head3 header_only
207  
208 Returns true of only the header was requested.
209  
210 =cut
211  
212 0 ▶sub header_only { 0 }
Subroutine header_only: not called CC=1 SCAR=6.9
Pod documented
213  
214 0 ▶sub server_returns_object { 1 }
Subroutine server_returns_object: not called CC=1 SCAR=6.9
Pod undocumented
215  
216 =head3 unescape
217  
218 Unescape an encoded uri.
219  
220 =cut
221  
222 sub unescape
223 0 ▶{
Subroutine unescape: not called CC=1 SCAR=6.9
Pod documented
224 0 my ($self, $string) = @_;
225  
226 0 return uri_unescape($string);
227 }
228  
229 =head3 server_return
230  
231 This function defines what is returned to the server at the end of a dispatch.
232 For nginx, this will be a status code, but in this test implementation we're
233 returning the actual server object itself, so we can evaluate it while testing
234  
235 =cut
236  
237 sub server_return
238 15 ▶{
Subroutine server_return: called CC=1 SCAR=0.0
Pod documented
239 15 my ($self, $what) = @_;
240  
241 15 return $self;
242 }
243  
244 0 ▶sub close_connection { 1 }
Subroutine close_connection: not called CC=1 SCAR=6.9
Pod undocumented
245  
246 =head1 AUTHORS
247  
248 Bizowie <http://bizowie.com>
249  
250 =head1 COPYRIGHT AND LICENSE
251  
252 Copyright (C) 2013 Bizowie
253  
254 This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
255  
256 =cut
257  
258 1 1;
« lib/Drogo/Server.pm ↑ Summary blib/lib/Drogo.pm »