File Coverage

blib/lib/Web/Request/Upload.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 18 100.0


line stmt bran cond sub pod time code
1             package Web::Request::Upload;
2             BEGIN {
3 4     4   15043 $Web::Request::Upload::AUTHORITY = 'cpan:DOY';
4             }
5             {
6             $Web::Request::Upload::VERSION = '0.11';
7             }
8 4     4   416 use Moose;
  4         385598  
  4         48  
9             # ABSTRACT: class representing a file upload
10              
11 4     4   25168 use HTTP::Headers;
  4         5598  
  4         119  
12              
13 4     4   1760 use Web::Request::Types;
  4         21  
  4         922  
14              
15              
16             has headers => (
17             is => 'ro',
18             isa => 'Web::Request::Types::HTTP::Headers',
19             coerce => 1,
20             handles => ['content_type'],
21             );
22              
23             has tempname => (
24             is => 'ro',
25             isa => 'Str',
26             );
27              
28             has size => (
29             is => 'ro',
30             isa => 'Int',
31             );
32              
33             has filename => (
34             is => 'ro',
35             isa => 'Str',
36             );
37              
38             # XXX Path::Class, and just make this a delegation?
39             # would that work at all on win32?
40             has basename => (
41             is => 'ro',
42             isa => 'Str',
43             lazy => 1,
44             default => sub {
45             my $self = shift;
46              
47             require File::Spec::Unix;
48              
49             my $basename = $self->{filename};
50             $basename =~ s{\\}{/}g;
51             $basename = (File::Spec::Unix->splitpath($basename))[2];
52             $basename =~ s{[^\w\.-]+}{_}g;
53              
54             return $basename;
55             },
56             );
57              
58             __PACKAGE__->meta->make_immutable;
59 4     4   34 no Moose;
  4         10  
  4         33  
60              
61              
62             1;
63              
64             __END__
65              
66             =pod
67              
68             =head1 NAME
69              
70             Web::Request::Upload - class representing a file upload
71              
72             =head1 VERSION
73              
74             version 0.11
75              
76             =head1 SYNOPSIS
77              
78             use Web::Request;
79              
80             my $app = sub {
81             my ($env) = @_;
82             my $req = Web::Request->new_from_env($env);
83             my $upload = $req->uploads->{avatar};
84             };
85              
86             =head1 DESCRIPTION
87              
88             This class represents a single uploaded file, generally from an C<< <input
89             type="file" /> >> element. You most likely don't want to create instances of
90             this class yourself; they will be created for you via the C<uploads> method on
91             L<Web::Request>.
92              
93             =head1 METHODS
94              
95             =head2 headers
96              
97             Returns an L<HTTP::Headers> object containing the headers specific to this
98             upload.
99              
100             =head2 content_type
101              
102             Returns the MIME type of the uploaded file. Corresponds to the C<Content-Type>
103             header.
104              
105             =head2 tempname
106              
107             Returns the local on-disk filename where the uploaded file was saved.
108              
109             =head2 size
110              
111             Returns the size of the uploaded file.
112              
113             =head2 filename
114              
115             Returns the preferred filename of the uploaded file.
116              
117             =head2 basename
118              
119             Returns the filename portion of C<filename>, with all directory components
120             stripped.
121              
122             =head1 AUTHOR
123              
124             Jesse Luehrs <doy@tozt.net>
125              
126             =head1 COPYRIGHT AND LICENSE
127              
128             This software is copyright (c) 2013 by Jesse Luehrs.
129              
130             This is free software; you can redistribute it and/or modify it under
131             the same terms as the Perl 5 programming language system itself.
132              
133             =cut