ASP/Request.pm

filter: Statementstmt 27.5% 16 / 58 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 38.4% 5 / 13 Podpod 57.1% 4 / 7 totaltotal 25.2% 25 / 99 CC 13 SCAR 26.2
CC
13
Cov
21%
Form
30.0
Cookies
20.0
FileUpload
17.5
CRAP 13.7
« 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 {
12 0 ▶ my ($class, %args) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
13
14 0 my $s = bless {
15 }, $class;
16
17 0 return $s;
18 }# end new()
19  
20  
21 #==============================================================================
22 sub context
23 {
24 0 ▶ $Apache2::ASP::HTTPContext::ClassName->current;
Subroutine context: not called CC=1 SCAR=6.9
Pod undocumented
25 }# end context()
26  
27  
28 #==============================================================================
29 sub ServerVariables
30 {
31 0 ▶ my $s = shift;
Subroutine ServerVariables: not called CC=2 SCAR=17.9
Pod documented
32 0 ▶ @_ ? $ENV{$_[0]} : \%ENV;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
33 }# end ServerVariables()
34  
35  
36 #==============================================================================
37 sub Form
38 {
39 0 ▶ my $s = shift;
Subroutine Form: not called CC=5 SCAR=34.0
Pod documented
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 {
61 0 ▶ my $s = shift;
Subroutine QueryString: not called CC=1 SCAR=6.9
Pod documented
62
63 0 return $s->context->r->args;
64 }# end QueryString()
65  
66  
67 #==============================================================================
68 sub Cookies
69 {
70 0 ▶ my $s = shift;
Subroutine Cookies: not called CC=4 SCAR=30.0
Pod documented
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 {
88 0 ▶ my ($s, $field, $arg) = @_;
Subroutine FileUpload: not called CC=5 SCAR=28.6
Pod undocumented
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 %info = (
103 ContentType => $cgi->upload_info( $field, 'mime' ),
104 FileHandle => $ifh,
105 0 BrowserFile => $s->Form->{ $field } . "",
106 'Content-Disposition' => 'attachment',
107 'Mime-Header' => $cgi->upload_info( $field, 'mime' ),
108 );
109 }
110 else
111 {
112 0 $upInfo = $cgi->uploadInfo( $ifh );
113 23 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
114 %info = (
115 ContentType => $upInfo->{'Content-Type'},
116 FileHandle => $ifh,
117 BrowserFile => $s->Form->{ $field } . "",
118 'Content-Disposition' => $upInfo->{'Content-Disposition'},
119 'Mime-Header' => $upInfo->{type},
120 0 );
121 }# end if()
122
123 0 ▶ if( wantarray )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
124 {
125 0 return %info;
126 }
127 else
128 {
129 0 ▶ if( $arg )
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) { } 0 0 0
130 {
131 0 return $info{ $arg };
132 }
133 else
134 {
135 0 return $ifh;
136 }# end if()
137 }# end if()
138  
139 }# end FileUpload()
140  
141  
142 #==============================================================================
143 sub DESTROY
144 {
145 0 ▶ my $s = shift;
Subroutine DESTROY: not called CC=1 SCAR=6.9
146 0 undef(%$s);
147 }# end DESTROY()
148  
149 23 1;# return true:
150  
151 =pod
152  
153 =head1 NAME
154  
155 Apache2::ASP::Request - Incoming request object.
156  
157 =head1 SYNOPSIS
158  
159 my $form_args = $Request->Form;
160
161 my $querystring = $Request->QueryString;
162
163 my $cookies = $Request->Cookies;
164
165 my $cookie = $Request->Cookies('name');
166
167 my $vars = $Request->ServerVariables;
168
169 my $var = $Request->ServerVariables('HTTP_HOST');
170  
171 =head1 DESCRIPTION
172  
173 The request represents a wrapper around incoming form, querystring and cookie data.
174  
175 =head1 PUBLIC METHODS
176  
177 =head2 ServerVariables( [$name] )
178  
179 If called with no arguments, returns C<%ENV>. If called with an argument, returns
180 C<$ENV{$name}> where C<$name> is the value of the argument.
181  
182 =head2 Cookies( [$name] )
183  
184 If called with no arguments, returns a hash of all cookies. Otherwise, returns
185 the value of the cookie named C<$name>.
186  
187 =head1 PUBLIC PROPERTIES
188  
189 =head2 Form
190  
191 Returns a hashref of all querystring and form data.
192  
193 =head2 QueryString
194  
195 Returns the querystring portion of the current request.
196  
197 =head1 BUGS
198
199 It's possible that some bugs have found their way into this release.
200
201 Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP> to submit bug reports.
202
203 =head1 HOMEPAGE
204
205 Please visit the Apache2::ASP homepage at L<http://www.devstack.com/> to see examples
206 of Apache2::ASP in action.
207  
208 =head1 AUTHOR
209  
210 John Drago <jdrago_999@yahoo.com>
211  
212 =head1 COPYRIGHT
213  
214 Copyright 2008 John Drago. All rights reserved.
215  
216 =head1 LICENSE
217  
218 This software is Free software and is licensed under the same terms as perl itself.
219  
220 =cut
221  
« ASP/ConfigNode/Web.pm ↑ Summary ASP/ConfigFinder.pm »