ASP/Mock/RequestRec.pm

filter: Statementstmt 32.2% 19 / 59 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 24.0% 6 / 25 Podpod 57.8% 11 / 19 totaltotal 31.3% 36 / 115 CC 7 SCAR 12.1
CC
7
Cov
27%
pnotes
6.0
status
6.0
uri
6.0
CRAP 3.4
« ASP/Test/UploadObject.pm ↑ Summary ASP/HTTPContext/HandlerRunner.pm »
1  
2 package Apache2::ASP::Mock::RequestRec;
3  
4 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 23 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 23 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 23 ▶use Apache2::ASP::Mock::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 23 ▶use Apache2::ASP::Mock::Pool;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 23 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 #==============================================================================
13 sub new
14 {
15 0 ▶ my ($class) = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
16  
17 0 my $s = bless {
18 buffer => '',
19 uri => '',
20 headers_out => HTTP::Headers->new,
21 headers_in => { },
22 pnotes => { },
23 status => 200,
24 cleanup_handlers => [ ],
25 pool => Apache2::ASP::Mock::Pool->new(),
26 connection => Apache2::ASP::Mock::Connection->new(),
27 }, $class;
28 0 $s->{err_headers_out} = $s->{headers_out};
29 0 return $s;
30 }# end new()
31  
32  
33 #==============================================================================
34 sub push_handlers
35 {
36 0 ▶ my ($s, $ref, @args) = @_;
Subroutine push_handlers: not called CC=1 SCAR=6.9
Pod undocumented
37
38 0 push @{$s->{cleanup_handlers}}, {
39 subref => $ref,
40 args => \@args,
41 };
42 }# end push_handlers()
43  
44  
45 #==============================================================================
46 sub filename
47 {
48 0 ▶ my $s = shift;
Subroutine filename: not called CC=1 SCAR=6.9
Pod documented
49
50 0 my $config = Apache2::ASP::HTTPContext->current->config;
51
52 0 return $config->web->www_root . $s->uri;
53 }# end filename()
54  
55  
56 #==============================================================================
57 sub pnotes
58 {
59 0 ▶ my $s = shift;
Subroutine pnotes: not called CC=2 SCAR=17.9
Pod documented
60 0 my $key = shift;
61
62 0 ▶ @_ ? $s->{pnotes}->{$key} = shift : $s->{pnotes}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
63 }# end pnotes()
64  
65  
66 #==============================================================================
67 sub buffer
68 {
69 0 ▶ $_[0]->{buffer};
Subroutine buffer: not called CC=1 SCAR=6.9
Pod documented
70 }# end buffer()
71  
72  
73 #==============================================================================
74 sub pool
75 {
76 0 ▶ $_[0]->{pool};
Subroutine pool: not called CC=1 SCAR=6.9
Pod documented
77 }# end buffer()
78  
79  
80 #==============================================================================
81 sub status
82 {
83 0 ▶ my $s = shift;
Subroutine status: not called CC=2 SCAR=17.9
Pod documented
84
85 0 ▶ @_ ? $s->{status} = shift : $s->{status};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
86 }# end status()
87  
88  
89 #==============================================================================
90 sub uri
91 {
92 0 ▶ my $s = shift;
Subroutine uri: not called CC=2 SCAR=17.9
Pod documented
93
94 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
95 {
96 0 $s->{uri} = shift;
97 # Should we also set $ENV{REQUEST_URI} here?
98 }
99 else
100 {
101 0 return $s->{uri};
102 }# end if()
103 }# end uri()
104  
105  
106 #==============================================================================
107 sub args
108 {
109 0 ▶ my $s = shift;
Subroutine args: not called CC=2 SCAR=17.9
Pod undocumented
110 0 ▶ @_ ? $s->{args} = shift : $s->{args};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
111 }# end args()
112  
113  
114 #==============================================================================
115 sub method
116 {
117 0 ▶ my $s = shift;
Subroutine method: not called CC=2 SCAR=17.9
Pod documented
118 0 ▶ @_ ? $s->{method} = shift : $s->{method};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
119 }# end method()
120  
121  
122 #==============================================================================
123 #XXX Not documented.
124 sub headers_out
125 {
126 0 ▶ $_[0]->{headers_out};
Subroutine headers_out: not called CC=1 SCAR=6.9
Pod undocumented
127 }# end headers_out()
128  
129  
130 #==============================================================================
131 #XXX Not documented.
132 sub err_headers_out
133 {
134 0 ▶ $_[0]->{headers_out};
Subroutine err_headers_out: not called CC=1 SCAR=6.9
Pod undocumented
135 }# end err_headers_out()
136  
137  
138 #==============================================================================
139 #XXX Not documented.
140 sub headers_in
141 {
142 0 ▶ $_[0]->{headers_in};
Subroutine headers_in: not called CC=1 SCAR=6.9
Pod undocumented
143 }# end headers_out()
144  
145  
146 #==============================================================================
147 #XXX Not documented.
148 sub send_headers
149 {
150 0 ▶ my $s = shift;
Subroutine send_headers: not called CC=1 SCAR=6.9
Pod undocumented
151
152 0 my $buffer = delete($s->{buffer});
153 0 $s->print( join "\n", map { "$_: $s->{headers_out}->{$_}" } keys(%{$s->{headers_out}}) );
154 0 $s->{buffer} = $buffer;
155 }# end send_headers()
156  
157  
158 #==============================================================================
159 sub content_type
160 {
161 0 ▶ my $s = shift;
Subroutine content_type: not called CC=2 SCAR=17.9
Pod documented
162 0 ▶ @_ ? $s->{content_type} = shift : $s->{content_type};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
163 }# end content_type()
164  
165  
166 #==============================================================================
167 sub print
168 {
169 0 ▶ $_[0]->{buffer} .= $_[1];
Subroutine print: not called CC=1 SCAR=6.9
Pod documented
170 }# end print()
171  
172  
173 #==============================================================================
174 sub rflush
175 {
176 0 ▶ my $s = shift;
Subroutine rflush: not called CC=1 SCAR=6.9
Pod documented
177 #warn "$s: rflush()";
178 }# end rflush()
179  
180  
181 #==============================================================================
182 sub connection
183 {
184 0 ▶ $_[0]->{connection};
Subroutine connection: not called CC=1 SCAR=6.9
Pod documented
185 }# end connection()
186  
187  
188 #==============================================================================
189 sub document_root
190 {
191 0 ▶ $ENV{DOCUMENT_ROOT};
Subroutine document_root: not called CC=1 SCAR=6.9
Pod undocumented
192 }# end document_root()
193  
194 23 1;# return true:
195  
196 =pod
197  
198 =head1 NAME
199  
200 Apache2::ASP::Mock::RequestRec - Mimics the mod_perl2 Apache2::RequestRec object ($r)
201  
202 =head1 SYNOPSIS
203  
204 my $r = Apache2::ASP::HTTPContext->current->r;
205
206 $r->filename( '/index.asp' ); # '/usr/local/projects/mysite.com/htdocs/index.asp
207
208 $r->pnotes( foo => 'bar' ); # set foo = 'bar'
209 my $foo = $r->pnotes( 'foo' ); # get foo
210
211 my $output_buffer_contents = $r->buffer;
212
213 my $mock_apr_pool = $r->pool;
214
215 $r->status( '302 Found' );
216 my $status = $r->status;
217
218 my $uri = $r->uri;
219 $r->uri('/new.asp');
220
221 my $method = $r->method; # get/post
222
223 $r->content_type( 'text/html' );
224 my $type = $r->content_type;
225
226 my $mock_connection = $r->connection;
227
228 $r->print( 'some string' );
229
230 $r->rflush;
231  
232 =head1 DESCRIPTION
233  
234 This package provides "mock" access to what would normally be an L<Apache2::RequestRec> object -
235 known by the name C<$r> in a normal mod_perl2 environment.
236  
237 This package exists only to provide a layer of abstraction for L<Apache2::ASP::API>
238 and L<Apache2::ASP::Test::Base>.
239  
240 B<NOTE>: The purpose of this package is only to mimic I<enough> of the functionality
241 of L<Apache2::RequestRec> to B<get by> without it - specifically during testing.
242  
243 If you require additional functionality, B<patches are welcome!>
244  
245 =head1 PUBLIC PROPERTIES
246  
247 =head2 filename
248  
249 Read-only. Returns the absolute filename for the current request - i.e. C</usr/local/projects/mysite.com/htdocs/index.asp>
250  
251 =head2 pnotes( $name [, $value ] )
252  
253 Read/Write. Set or get a variable for the duration of the current request.
254  
255 =head2 buffer
256  
257 Read-only. Returns the contents of the current output buffer.
258  
259 =head2 pool
260  
261 Read-only. Returns the current L<Apache2::ASP::Mock::Pool> object.
262  
263 =head2 status( [$new_status] )
264  
265 Read/Write. Set or get the HTTP status code, I<a la> L<Apache2::Const>.
266  
267 =head2 uri( [$new_uri] )
268  
269 Read/Write. Set or get the request URI.
270  
271 =head2 method
272  
273 Read-only. Gets the request method - i.e. 'get' or 'post'.
274  
275 =head2 content_type( [$new_content_type] )
276  
277 Read/Write. Set or get the B<outgoing> C<content-type> header.
278  
279 =head2 connection
280  
281 Read-only. Returns the current L<Apache2::ASP::Mock::Connection> object.
282  
283 =head1 PUBLIC METHODS
284  
285 =head2 print( $string )
286  
287 Adds C<$string> to the output buffer.
288  
289 =head2 rflush( )
290  
291 Does nothing. Here only to maintain compatibility with a normal mod_perl2 environment.
292  
293 =head1 BUGS
294
295 It's possible that some bugs have found their way into this release.
296
297 Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP> to submit bug reports.
298
299 =head1 HOMEPAGE
300
301 Please visit the Apache2::ASP homepage at L<http://www.devstack.com/> to see examples
302 of Apache2::ASP in action.
303  
304 =head1 AUTHOR
305  
306 John Drago <jdrago_999@yahoo.com>
307  
308 =head1 COPYRIGHT
309  
310 Copyright 2008 John Drago. All rights reserved.
311  
312 =head1 LICENSE
313  
314 This software is Free software and is licensed under the same terms as perl itself.
315  
316 =cut
317  
« ASP/Test/UploadObject.pm ↑ Summary ASP/HTTPContext/HandlerRunner.pm »