| 1 | |||||||||||||||||||||||||||||||||||||||
| 2 | package ASP4::Mock::RequestRec; | ||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use warnings 'all'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 15 | ▶ | use ASP4::Mock::Pool; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use ASP4::Mock::Connection; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use ASP4::ConfigLoader; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||
| 12 | sub new | ||||||||||||||||||||||||||||||||||||||
| 13 | 5145 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 14 | 5145 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||
| 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 | 5145 | ▶ | pool => ASP4::Mock::Pool->new(), | ||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$args{'uri'} || $ENV{'REQUEST_URI'}
$args{'args'} || $ENV{'QUERY_STRING'}
MC/DC0%0/2
$args{'uri'} || $ENV{'REQUEST_URI'}
$args{'uri'}
$ENV{'REQUEST_URI'}
MC/DC50%1/2
$args{'args'} || $ENV{'QUERY_STRING'}
$args{'args'}
$ENV{'QUERY_STRING'}
Truth table33%1/3
A || B
A= $args{'uri'}B= $ENV{'REQUEST_URI'}
Truth table66%2/3
A || B
A= $args{'args'}B= $ENV{'QUERY_STRING'}
| |||||||||||||||||||||||||||||||||||||||
| 28 | connection => ASP4::Mock::Connection->new(), | ||||||||||||||||||||||||||||||||||||||
| 29 | }, $class; | ||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | 5145 | weaken($s->{connection}); | |||||||||||||||||||||||||||||||||||||
| 32 | 5145 | $s->{err_headers_out} = $s->{headers_out}; | |||||||||||||||||||||||||||||||||||||
| 33 | 5145 | $s->{filename} = $s->document_root . $s->uri; | |||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 5145 | return $s; | |||||||||||||||||||||||||||||||||||||
| 36 | }# end new() | ||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||
| 39 | # Public read-write properties: | ||||||||||||||||||||||||||||||||||||||
| 40 | sub pnotes | ||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
pnotes: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | @_ ? $s->{pnotes}->{$name} = shift : $s->{pnotes}->{$name}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 45 | }# end pnotes() | ||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||
| 47 | sub uri | ||||||||||||||||||||||||||||||||||||||
| 48 | 15441 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
uri: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 49 | 15441 | my $s = shift; | |||||||||||||||||||||||||||||||||||||
| 50 | 15441 | ▶ | @_ ? $s->{uri} = shift : $s->{uri}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 51 | }# end uri() | ||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||
| 53 | sub args | ||||||||||||||||||||||||||||||||||||||
| 54 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
args: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 55 | 14 | my $s = shift; | |||||||||||||||||||||||||||||||||||||
| 56 | 14 | ▶ | @_ ? $s->{args} = shift : $s->{args}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 57 | }# end args() | ||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||
| 59 | 5148 | ▶ | sub status { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
status: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 60 | 5148 | my $s = shift; | |||||||||||||||||||||||||||||||||||||
| 61 | 5148 | ▶ | @_ ? $s->{status} = +shift : $s->{status}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 62 | }# end status() | ||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | # Public read-only properties: | ||||||||||||||||||||||||||||||||||||||
| 66 | 10290 | ▶ | 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 | 5130 | ▶ | sub pool { shift->{pool} } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
pool: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 69 | 1103 | ▶ | sub connection { shift->{connection} } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
connection: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 70 | 5152 | ▶ | sub headers_out { shift->{headers_out} } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
headers_out: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub headers_in { shift->{headers_in} } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
headers_in: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 72 | 11334 | ▶ | sub err_headers_out { shift->{err_headers_out} } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
err_headers_out: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||
| 74 | 5145 | ▶ | sub buffer { shift->{buffer} } # Not documented: | ||||||||||||||||||||||||||||||||||||
|
Subroutine
buffer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||
| 77 | # Public methods: | ||||||||||||||||||||||||||||||||||||||
| 78 | 10288 | ▶ | sub print { my ($s,$str) = @_; $s->{buffer} .= $str; } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 79 | sub content_type | ||||||||||||||||||||||||||||||||||||||
| 80 | 5152 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
content_type: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 81 | 5152 | my ($s, $type) = @_; | |||||||||||||||||||||||||||||||||||||
| 82 | 5152 | ▶ | return $s->headers_out->{'content-type'} unless $type; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 83 | 5152 | $s->headers_out->{'content-type'} = $type; | |||||||||||||||||||||||||||||||||||||
| 84 | }# end content_type() | ||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | 15432 | ▶ | sub rflush { } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
rflush: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | 15 | 1;# return true: | |||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||
| 90 | =pod | ||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||
| 92 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | ASP4::Mock::RequestRec - Mimic an Apache2::RequestRec object | ||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||
| 96 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | When an ASP4 request is executed outside of a mod_perl2 environment, it uses an | ||||||||||||||||||||||||||||||||||||||
| 99 | instance of C<ASP4::Mock::RequestRec> in place of the L<Apache2::RequestRec> it | ||||||||||||||||||||||||||||||||||||||
| 100 | would otherwise have. | ||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | =head1 PUBLIC PROPERTIES | ||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | =head2 pnotes( $name [, $value ] ) | ||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | Sets or gets the value of a named "pnote" for the duration of the request. | ||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||
| 108 | Example: | ||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||
| 110 | $r->pnotes( foo => "foovalue" ); | ||||||||||||||||||||||||||||||||||||||
| 111 | my $val = $r->pnotes( 'foo' ); | ||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||
| 113 | =head2 args( [$new_args] ) | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | Sets or gets the querystring for the request. | ||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||
| 117 | Example: | ||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||
| 119 | my $str = $r->args(); | ||||||||||||||||||||||||||||||||||||||
| 120 | $r->args( 'foo=bar&baz=bux' ); | ||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||
| 122 | =head2 uri( [$new_uri] ) | ||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | Sets or gets the URI for the current request: | ||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | Example: | ||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||
| 128 | my $uri = $r->uri; | ||||||||||||||||||||||||||||||||||||||
| 129 | $r->uri( '/path/to/page.asp' ); | ||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||
| 131 | =head2 document_root( ) | ||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||
| 133 | Gets the document root for the server. This is the same as $config->web->www_root. | ||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||
| 135 | my $root = $r->document_root; # /var/www/mysite.com/htdocs | ||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||
| 137 | =head2 method( ) | ||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | Gets the request method for the current request. Eg: C<GET> or C<POST>. | ||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||
| 141 | if( $r->method eq 'GET' ) { | ||||||||||||||||||||||||||||||||||||||
| 142 | # It's a "GET" request: | ||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||
| 144 | elsif( $r->method eq 'POST' ) { | ||||||||||||||||||||||||||||||||||||||
| 145 | # It's a "POST" request: | ||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||
| 148 | =head2 pool( ) | ||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||
| 150 | Returns the current L<ASP4::Mock::Pool> object. | ||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||
| 152 | my $pool = $r->pool; | ||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||
| 154 | =head2 connection( ) | ||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | Returns the current L<ASP4::Mock::Connection> object. | ||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||
| 158 | my $connection = $r->connection; | ||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||
| 160 | =head2 headers_out( ) | ||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||
| 162 | Returns a hashref representing the outgoing headers. | ||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||
| 164 | =head2 err_headers_out( ) | ||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||
| 166 | Returns a hashref representing the outgoing headers. | ||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||
| 168 | =head2 status( [$new_status] ) | ||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||
| 170 | Sets or gets the status code for the response. 200 for "OK", 301 for "Moved" - 404 for "not found" etc. | ||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||
| 172 | =head2 content_type( [$new_content_type] ) | ||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||
| 174 | Sets or gets the mime-header for the outgoing response. Default is C<text/plain>. | ||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||
| 176 | =head1 PUBLIC METHODS | ||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||
| 178 | =head2 print( $str ) | ||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||
| 180 | Adds C<$str> to the outgoing response buffer. | ||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||
| 182 | =head2 rflush( ) | ||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||
| 184 | Does nothing. | ||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||
| 186 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||
| 188 | It's possible that some bugs have found their way into this release. | ||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||
| 190 | Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ASP4> to submit bug reports. | ||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||
| 192 | =head1 HOMEPAGE | ||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||
| 194 | Please visit the ASP4 homepage at L<http://0x31337.org/code/> to see examples | ||||||||||||||||||||||||||||||||||||||
| 195 | of ASP4 in action. | ||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||