ASP4/Mock/RequestRec.pm

filter: Statementstmt 62.2% 28 / 45 Branchbran 10.0% 1 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 42.8% 9 / 21 Podpod 86.6% 13 / 15 totaltotal 52.4% 53 / 101 CC 8 SCAR 11.0
CC
8
Cov
51%
pnotes
6.0
args
6.0
status
6.0
CRAP 3.0
« ASP4/OutBuffer.pm ↑ Summary ASP4/FileUpload.pm »
1  
2 package ASP4::Mock::RequestRec;
3  
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use ASP4::Mock::Pool;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use ASP4::Mock::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use ASP4::ConfigLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 sub new
13 {
14 1 ▶ my ($class, %args) = @_;
Subroutine new: called CC=3 SCAR=12.0
Pod undocumented
15
16 my $s = bless {
17 status => 200,
18 content_type => 'text/plain',
19 buffer => '',
20 document_root => ASP4::ConfigLoader->load()->web->www_root,
21 headers_in => { },
22 headers_out => { },
23 uri => $args{uri} || $ENV{REQUEST_URI},
24 args => $args{args} || $ENV{QUERY_STRING},
25 pnotes => { },
26 method => $args{method},
27 1 ▶ pool => ASP4::Mock::Pool->new(),
Condition33%2/6
$args{'uri'} || $ENV{'REQUEST_URI'}
l!l&&r!l&&!r
100
$args{'args'} || $ENV{'QUERY_STRING'}
l!l&&r!l&&!r
001
MC/DC0%0/2
$args{'uri'} || $ENV{'REQUEST_URI'}
$args{'uri'} $ENV{'REQUEST_URI'}
MC/DC0%0/2
$args{'args'} || $ENV{'QUERY_STRING'}
$args{'args'} $ENV{'QUERY_STRING'}
Truth table33%1/3
A || B
A= $args{'uri'}B= $ENV{'REQUEST_URI'}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $args{'args'}B= $ENV{'QUERY_STRING'}
ABresult
1X1
011
000
28 connection => ASP4::Mock::Connection->new(),
29 }, $class;
30 1 weaken($s->{connection});
31 1 $s->{err_headers_out} = $s->{headers_out};
32
33 1 $s->{filename} = $s->document_root . $s->uri;
34
35 1 return $s;
36 }# end new()
37  
38  
39 # Public read-write properties:
40 sub pnotes
41 {
42 0 ▶ my $s = shift;
Subroutine pnotes: not called CC=2 SCAR=17.9
Pod documented
43 0 my $name = shift;
44 0 ▶ @_ ? $s->{pnotes}->{$name} = shift : $s->{pnotes}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
45 }# end pnotes()
46  
47 sub uri
48 {
49 1 ▶ my $s = shift;
Subroutine uri: called CC=2 SCAR=7.2
Pod documented
50 1 ▶ @_ ? $s->{uri} = shift : $s->{uri};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 1 1
51 }# end uri()
52  
53 sub args
54 {
55 0 ▶ my $s = shift;
Subroutine args: not called CC=2 SCAR=17.9
Pod documented
56 0 ▶ @_ ? $s->{args} = shift : $s->{args};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
57 }# end args()
58  
59 sub status {
60 0 ▶ my $s = shift;
Subroutine status: not called CC=2 SCAR=17.9
Pod documented
61 0 ▶ @_ ? $s->{status} = +shift : $s->{status};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
62 }# end status()
63  
64  
65 # Public read-only properties:
66 1 ▶sub document_root { shift->{document_root} }
Subroutine document_root: called CC=1 SCAR=0.0
Pod documented
67 0 ▶sub method { uc( shift->{method} ) }
Subroutine method: not called CC=1 SCAR=6.9
Pod documented
68 0 ▶sub pool { shift->{pool} }
Subroutine pool: not called CC=1 SCAR=6.9
Pod documented
69 0 ▶sub connection { shift->{connection} }
Subroutine connection: not called CC=1 SCAR=6.9
Pod documented
70 0 ▶sub headers_out { shift->{headers_out} }
Subroutine headers_out: not called CC=1 SCAR=6.9
Pod documented
71 0 ▶sub err_headers_out { shift->{err_headers_out} }
Subroutine err_headers_out: not called CC=1 SCAR=6.9
Pod documented
72  
73 0 ▶sub buffer { shift->{buffer} } # Not documented:
Subroutine buffer: not called CC=1 SCAR=6.9
Pod undocumented
74  
75  
76 # Public methods:
77 0 ▶sub print { my ($s,$str) = @_; $s->{buffer} .= $str; }
Subroutine print: not called CC=1 SCAR=6.9
Pod documented
78 0 ▶sub content_type { my $s = shift; @_ ? $s->{content_type} = +shift : $s->{content_type} }
Subroutine content_type: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
79  
80 ▶sub rflush { }
Subroutine rflush: not called CC=1 SCAR=0.0
Pod documented
81  
82 8 1;# return true:
83  
84 =pod
85  
86 =head1 NAME
87  
88 ASP4::Mock::RequestRec - Mimic an Apache2::RequestRec object
89  
90 =head1 DESCRIPTION
91  
92 When an ASP4 request is executed outside of a mod_perl2 environment, it uses an
93 instance of C<ASP4::Mock::RequestRec> in place of the L<Apache2::RequestRec> it
94 would otherwise have.
95  
96 =head1 PUBLIC PROPERTIES
97  
98 =head2 pnotes( $name [, $value ] )
99  
100 Sets or gets the value of a named "pnote" for the duration of the request.
101  
102 Example:
103  
104 $r->pnotes( foo => "foovalue" );
105 my $val = $r->pnotes( 'foo' );
106  
107 =head2 args( [$new_args] )
108  
109 Sets or gets the querystring for the request.
110  
111 Example:
112  
113 my $str = $r->args();
114 $r->args( 'foo=bar&baz=bux' );
115  
116 =head2 uri( [$new_uri] )
117  
118 Sets or gets the URI for the current request:
119  
120 Example:
121  
122 my $uri = $r->uri;
123 $r->uri( '/path/to/page.asp' );
124  
125 =head2 document_root( )
126  
127 Gets the document root for the server. This is the same as $config->web->www_root.
128  
129 my $root = $r->document_root; # /var/www/mysite.com/htdocs
130  
131 =head2 method( )
132  
133 Gets the request method for the current request. Eg: C<GET> or C<POST>.
134  
135 if( $r->method eq 'GET' ) {
136 # It's a "GET" request:
137 }
138 elsif( $r->method eq 'POST' ) {
139 # It's a "POST" request:
140 }
141  
142 =head2 pool( )
143  
144 Returns the current L<ASP4::Mock::Pool> object.
145  
146 my $pool = $r->pool;
147  
148 =head2 connection( )
149  
150 Returns the current L<ASP4::Mock::Connection> object.
151  
152 my $connection = $r->connection;
153  
154 =head2 headers_out( )
155  
156 Returns a hashref representing the outgoing headers.
157  
158 =head2 err_headers_out( )
159  
160 Returns a hashref representing the outgoing headers.
161  
162 =head2 status( [$new_status] )
163  
164 Sets or gets the status code for the response. 200 for "OK", 301 for "Moved" - 404 for "not found" etc.
165  
166 =head2 content_type( [$new_content_type] )
167  
168 Sets or gets the mime-header for the outgoing response. Default is C<text/plain>.
169  
170 =head1 PUBLIC METHODS
171  
172 =head2 print( $str )
173  
174 Adds C<$str> to the outgoing response buffer.
175  
176 =head2 rflush( )
177  
178 Does nothing.
179  
180 =cut
181  
« ASP4/OutBuffer.pm ↑ Summary ASP4/FileUpload.pm »