| 1 | |||||||||||
| 2 | package ASP4::Request; | ||||||||||
| 3 | |||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 9 | ▶ | use warnings 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | |||||||||||
| 8 | sub new | ||||||||||
| 9 | { | ||||||||||
| 10 | 0 | ▶ | my ($class, %args) = @_; | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 11 | |||||||||||
| 12 | 0 | return bless { | |||||||||
| 13 | %args, | ||||||||||
| 14 | form => scalar( $class->context->cgi->Vars ), | ||||||||||
| 15 | }, $class; | ||||||||||
| 16 | }# end new() | ||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | sub context { ASP4::HTTPContext->current } | ||||||||
|
Subroutine
context: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 20 | |||||||||||
| 21 | # Not documented - for a reason (want to deprecate): | ||||||||||
| 22 | 0 | ▶ | sub Form { shift->{form} } | ||||||||
|
Subroutine
Form: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 23 | |||||||||||
| 24 | # Not documented - for a reason (want to deprecate): | ||||||||||
| 25 | 0 | ▶ | sub QueryString { shift->context->cgi->query_string() } | ||||||||
|
Subroutine
QueryString: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 26 | |||||||||||
| 27 | sub Cookies { | ||||||||||
| 28 | 0 | ▶ | my ($s, $name) = @_; | ||||||||
|
Subroutine
Cookies: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 29 | 0 | ▶ | $name ? $s->context->cgi->cookie( $name ) : $s->context->cgi->cookie; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub ServerVariables { $ENV{ $_[1] } } | ||||||||
|
Subroutine
ServerVariables: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 33 | |||||||||||
| 34 | sub FileUpload | ||||||||||
| 35 | { | ||||||||||
| 36 | 0 | ▶ | my ($s, $field) = @_; | ||||||||
|
Subroutine
FileUpload: not called CC=3 SCAR=17.7
Pod
documented
| |||||||||||
| 37 | |||||||||||
| 38 | 0 | ▶ | my $ifh = $s->context->cgi->upload($field) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | or return; | ||||||||||
| 40 | 0 | my %info = ( ); | |||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | if( my $upInfo = eval { $s->context->cgi->uploadInfo( $ifh ) } ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | { | ||||||||||
| 44 | 9 | ▶ | no warnings 'uninitialized'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 45 | %info = ( | ||||||||||
| 46 | ContentType => $upInfo->{'Content-Type'}, | ||||||||||
| 47 | FileHandle => $ifh, | ||||||||||
| 48 | FileName => $s->{form}->{ $field } . "", | ||||||||||
| 49 | 0 | ContentDisposition => $upInfo->{'Content-Disposition'}, | |||||||||
| 50 | ); | ||||||||||
| 51 | } | ||||||||||
| 52 | else | ||||||||||
| 53 | { | ||||||||||
| 54 | 9 | ▶ | no warnings 'uninitialized'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 55 | %info = ( | ||||||||||
| 56 | ContentType => $s->context->cgi->{uploads}->{ $field }->{headers}->{'Content-Type'}, | ||||||||||
| 57 | FileHandle => $ifh, | ||||||||||
| 58 | FileName => $s->context->cgi->{uploads}->{ $field }->{filename}, | ||||||||||
| 59 | 0 | ContentDisposition => 'attachment', | |||||||||
| 60 | ); | ||||||||||
| 61 | }# end if() | ||||||||||
| 62 | |||||||||||
| 63 | 0 | require ASP4::FileUpload; | |||||||||
| 64 | 0 | return ASP4::FileUpload->new( %info ); | |||||||||
| 65 | }# end FileUpload() | ||||||||||
| 66 | |||||||||||
| 67 | |||||||||||
| 68 | sub DESTROY | ||||||||||
| 69 | { | ||||||||||
| 70 | 0 | ▶ | my $s = shift; | ||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||
| 71 | 0 | undef(%$s); | |||||||||
| 72 | }# end DESTROY() | ||||||||||
| 73 | |||||||||||
| 74 | 9 | 1;# return true: | |||||||||
| 75 | |||||||||||
| 76 | =pod | ||||||||||
| 77 | |||||||||||
| 78 | =head1 NAME | ||||||||||
| 79 | |||||||||||
| 80 | ASP4::Request - Interface to the incoming request | ||||||||||
| 81 | |||||||||||
| 82 | =head1 SYNOPSIS | ||||||||||
| 83 | |||||||||||
| 84 | if( my $cookie = $Request->Cookies('cust-email') ) { | ||||||||||
| 85 | # Greet our returning user: | ||||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | if( my $file = $Request->FileUpload('avatar_pic') ) { | ||||||||||
| 89 | # Handle the uploaded file: | ||||||||||
| 90 | $file->SaveAs( "/var/media/$Session->{user_id}/avatar/" . $file->FileName ); | ||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | if( $Request->ServerVariables("HTTPS") ) { | ||||||||||
| 94 | # We're under SSL: | ||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | =head1 DESCRIPTION | ||||||||||
| 98 | |||||||||||
| 99 | The intrinsic C<$Request> object provides a few easy-to-use methods to simplify | ||||||||||
| 100 | the processing of incoming requests - specifically file uploads and cookies. | ||||||||||
| 101 | |||||||||||
| 102 | =head1 METHODS | ||||||||||
| 103 | |||||||||||
| 104 | =head2 Cookies( [$name] ) | ||||||||||
| 105 | |||||||||||
| 106 | Returns a cookie by name, or all cookies if no name is provided. | ||||||||||
| 107 | |||||||||||
| 108 | =head2 ServerVariables( [$name] ) | ||||||||||
| 109 | |||||||||||
| 110 | A wrapper around the global C<%ENV> variable. | ||||||||||
| 111 | |||||||||||
| 112 | This means that: | ||||||||||
| 113 | |||||||||||
| 114 | $Request->ServerVariables('HTTP_HOST') | ||||||||||
| 115 | |||||||||||
| 116 | is the same as: | ||||||||||
| 117 | |||||||||||
| 118 | $ENV{HTTP_HOST} | ||||||||||
| 119 | |||||||||||
| 120 | =head2 FileUpload( $fieldname ) | ||||||||||
| 121 | |||||||||||
| 122 | Returns a L<ASP4::FileUpload> object that corresponds to the fieldname specified. | ||||||||||
| 123 | |||||||||||
| 124 | So...if your form has this: | ||||||||||
| 125 | |||||||||||
| 126 | <input type="file" name="my_uploaded_file" /> | ||||||||||
| 127 | |||||||||||
| 128 | Then you would get to it like this: | ||||||||||
| 129 | |||||||||||
| 130 | my $upload = $Request->FileUpload('my_uploaded-file'); | ||||||||||
| 131 | |||||||||||
| 132 | =cut | ||||||||||
| 133 | |||||||||||