File Coverage

blib/lib/Prancer/Request/Upload.pm
Criterion Covered Total %
statement 6 30 20.0
branch 0 2 0.0
condition n/a
subroutine 2 10 20.0
pod 5 8 62.5
total 13 50 26.0


line stmt bran cond sub pod time code
1             package Prancer::Request::Upload;
2              
3 4     4   18 use strict;
  4         4  
  4         109  
4 4     4   9 use warnings FATAL => 'all';
  4         4  
  4         1147  
5              
6             sub new {
7 0     0 0       my $class = shift;
8 0               my %args = @_;
9              
10 0               return bless({
11                     '_headers' => $args{'headers'},
12                     '_tempname' => $args{'tempname'},
13                     '_size' => $args{'size'},
14                     '_filename' => $args{'filename'},
15                 }, $class);
16             }
17              
18             sub filename {
19 0     0 1       my $self = shift;
20 0               return $self->{'_filename'};
21             }
22              
23             sub headers {
24 0     0 0       my $self = shift;
25 0               return $self->{'_headers'};
26             }
27              
28             sub size {
29 0     0 1       my $self = shift;
30 0               return $self->{'_size'};
31             }
32              
33             sub tempname {
34 0     0 0       my $self = shift;
35 0               return $self->{'_tempname'};
36             }
37              
38             sub path {
39 0     0 1       my $self = shift;
40 0               return $self->{'_tempname'};
41             }
42              
43             sub content_type {
44 0     0 1       my $self = shift;
45 0               return $self->{'_headers'}->content_type(@_);
46             }
47              
48             sub basename {
49 0     0 1       my $self = shift;
50              
51 0 0             unless (defined($self->{'_basename'})) {
52 0                   require File::Spec::Unix;
53 0                   my $basename = $self->{'_filename'};
54 0                   $basename =~ s|\\|/|gx;
55 0                   $basename = (File::Spec::Unix->splitpath($basename))[2];
56 0                   $basename =~ s|[^\w\.-]+|_|gx;
57 0                   $self->{'_basename'} = $basename;
58                 }
59              
60 0               return $self->{'_basename'};
61             }
62              
63             1;
64              
65             =head1 NAME
66            
67             Prancer::Request::Upload
68            
69             =head1 SYNOPSIS
70            
71             Uploads come from the L<Prancer::Request> object passed to your handler. They
72             can be used like this:
73            
74             # in your HTML
75             <form method="POST" enctype="multipart/form-data">
76             <input type="file" name="foobar" />
77             </form>
78            
79             # in the Prancer handler
80             my $upload = context->upload('foo');
81             my $upload = context->request->upload('bar');
82             $upload->size();
83             $upload->path();
84             $upload->content_type();
85             $upload->filename();
86             $upload->basename();
87            
88             =head1 ATTRIBUTES
89            
90             =over 4
91            
92             =item size
93            
94             Returns the size of uploaded file.
95            
96             =item path
97            
98             Returns the path to the temporary file where uploaded file is saved.
99            
100             =item content_type
101            
102             Returns the content type of the uploaded file.
103            
104             =item filename
105            
106             Returns the original filename in the client.
107            
108             =item basename
109            
110             Returns basename for "filename".
111            
112             =back
113            
114             =cut
115