ASP/Request.pm

filter: Statementstmt 29.0% 16 / 55 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 38.4% 5 / 13 Podpod 57.1% 4 / 7 totaltotal 25.5% 25 / 98 CC 14 SCAR 27.2
CC
14
Cov
21%
Form
30.0
FileUpload
23.5
Cookies
20.0
CRAP 15.2
« ASP/ConfigNode/Web.pm ↑ Summary ASP/ConfigFinder.pm »
1  
2 package Apache2::ASP::Request;
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  
8  
9 #==============================================================================
10 sub new
11 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
12 0 my ($class, %args) = @_;
13
14 0 my $s = bless {
15 }, $class;
16
17 0 return $s;
18 }# end new()
19  
20  
21 #==============================================================================
22 sub context
23 0 ▶{
Subroutine context: not called CC=1 SCAR=6.9
Pod undocumented
24 0 $Apache2::ASP::HTTPContext::ClassName->current;
25 }# end context()
26  
27  
28 #==============================================================================
29 sub ServerVariables
30 0 ▶{
Subroutine ServerVariables: not called CC=2 SCAR=17.9
Pod documented
31 0 my $s = shift;
32 0 ▶ @_ ? $ENV{$_[0]} : \%ENV;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
33 }# end ServerVariables()
34  
35  
36 #==============================================================================
37 sub Form
38 0 ▶{
Subroutine Form: not called CC=5 SCAR=34.0
Pod documented
39 0 my $s = shift;
40
41 0 ▶ if( my $cgi = $s->context->cgi )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cgi = $s->context->cgi) { } 0 0 0
42 {
43 0 my $form = { };
44 0 foreach my $param ( eval { $cgi->param } )
45 {
46 0 my @val = $cgi->param( $param );
47 0 ▶ $form->{$param} = scalar(@val) > 1 ? [ @val ] : $val[0];
Branch: 1 branch
BranchTrueFalseTotal
scalar @val > 1 ? : 0 0 0
48 }# end foreach()
49 0 return $s->{_form} = $form;
50 }
51 else
52 {
53 0 ▶ return $s->{_form} || { };
Condition0%0/2
$s->{'_form'} || {}
l!l
00
MC/DC0%0/1
$s->{'_form'} || {}
$s->{'_form'}
Truth table0%0/2
A
A= $s->{'_form'}
Aresult
11
00
54 }# end if()
55 }# end Form()
56  
57  
58 #==============================================================================
59 sub QueryString
60 0 ▶{
Subroutine QueryString: not called CC=1 SCAR=6.9
Pod documented
61 0 my $s = shift;
62
63 0 return $s->context->r->args;
64 }# end QueryString()
65  
66  
67 #==============================================================================
68 sub Cookies
69 0 ▶{
Subroutine Cookies: not called CC=4 SCAR=30.0
Pod documented
70 0 my $s = shift;
71
72 0 ▶ return { } unless $s->context->headers_in->{cookie};
Branch: 1 branch
BranchTrueFalseTotal
unless $s->context->headers_in->{"cookie"} 0 0 0
73
74 0 my %out = ( );
75 0 foreach my $item ( split /;\s*/, $s->context->headers_in->{cookie} )
76 {
77 0 my ( $name, $val ) = map { $s->context->cgi->unescape( $_ ) } split /\=/, $item;
78 0 $out{$name} = $val;
79 }# end foreach()
80
81 0 ▶ @_ ? $out{$_[0]} : \%out;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
82 }# end Cookies()
83  
84  
85 #==============================================================================
86 sub FileUpload
87 0 ▶{
Subroutine FileUpload: not called CC=6 SCAR=31.6
Pod undocumented
88 0 my ($s, $field) = @_;
89
90 0 ▶ confess "Request.FileUpload called without arguments"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 0 0
91 unless defined($field);
92
93 0 my $cgi = $s->context->cgi;
94
95 0 my $ifh = $cgi->upload($field);
96 0 my %info = ();
97 0 my $upInfo = { };
98
99 0 ▶ if( $cgi->isa('Apache2::ASP::SimpleCGI') )
Branch: 1 branch
BranchTrueFalseTotal
if ($cgi->isa('Apache2::ASP::SimpleCGI')) { } 0 0 0
100 {
101 23 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
102 0 ▶ my $up = $cgi->upload_info( $field, 'mime' )
Branch: 1 branch
BranchTrueFalseTotal
my $up = $cgi->upload_info($field, "mime") or return 0 0 0
103 or return;
104 %info = (
105 ContentType => $up,
106 FileHandle => $ifh,
107 0 FileName => $s->Form->{ $field } . "",
108 'ContentDisposition' => 'attachment',
109 # Mime-Header is deprecated as of v2.46
110 # 'Mime-Header' => $cgi->upload_info( $field, 'mime' ),
111 );
112 }
113 else
114 {
115 0 ▶ $upInfo = $cgi->uploadInfo( $ifh )
Branch: 1 branch
BranchTrueFalseTotal
$upInfo = $cgi->uploadInfo($ifh) or return 0 0 0
116 or return;
117 23 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
118 %info = (
119 ContentType => $upInfo->{'Content-Type'},
120 FileHandle => $ifh,
121 FileName => $s->Form->{ $field } . "",
122 0 'ContentDisposition' => $upInfo->{'Content-Disposition'},
123 # Mime-Header is deprecated as of v2.46
124 # 'Mime-Header' => $upInfo->{type},
125 );
126 }# end if()
127
128 0 ▶ return wantarray ? %info : \%info;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
129 }# end FileUpload()
130  
131  
132 #==============================================================================
133 sub DESTROY
134 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=6.9
135 0 my $s = shift;
136 0 undef(%$s);
137 }# end DESTROY()
138  
139 23 1;# return true:
140  
141 =pod
142  
143 =head1 NAME
144  
145 Apache2::ASP::Request - Incoming request object.
146  
147 =head1 SYNOPSIS
148  
149 my $form_args = $Request->Form;
150
151 my $querystring = $Request->QueryString;
152
153 my $cookies = $Request->Cookies;
154
155 my $cookie = $Request->Cookies('name');
156
157 my $vars = $Request->ServerVariables;
158
159 my $var = $Request->ServerVariables('HTTP_HOST');
160  
161 =head1 DESCRIPTION
162  
163 The request represents a wrapper around incoming form, querystring and cookie data.
164  
165 =head1 PUBLIC METHODS
166  
167 =head2 ServerVariables( [$name] )
168  
169 If called with no arguments, returns C<%ENV>. If called with an argument, returns
170 C<$ENV{$name}> where C<$name> is the value of the argument.
171  
172 =head2 Cookies( [$name] )
173  
174 If called with no arguments, returns a hash of all cookies. Otherwise, returns
175 the value of the cookie named C<$name>.
176  
177 =head1 PUBLIC PROPERTIES
178  
179 =head2 Form
180  
181 Returns a hashref of all querystring and form data.
182  
183 =head2 QueryString
184  
185 Returns the querystring portion of the current request.
186  
187 =head1 BUGS
188
189 It's possible that some bugs have found their way into this release.
190
191 Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP> to submit bug reports.
192
193 =head1 HOMEPAGE
194
195 Please visit the Apache2::ASP homepage at L<http://www.devstack.com/> to see examples
196 of Apache2::ASP in action.
197  
198 =head1 AUTHOR
199  
200 John Drago <jdrago_999@yahoo.com>
201  
202 =head1 COPYRIGHT
203  
204 Copyright 2008 John Drago. All rights reserved.
205  
206 =head1 LICENSE
207  
208 This software is Free software and is licensed under the same terms as perl itself.
209  
210 =cut
211  
« ASP/ConfigNode/Web.pm ↑ Summary ASP/ConfigFinder.pm »