Request/Upload.pm

filter: Statementstmt 100% 29 / 29 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 100% 35 / 35 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Request/Types.pm ↑ Summary
1 package Web::Request::Upload;
2 BEGIN {
3 5 ▶ $Web::Request::Upload::AUTHORITY = 'cpan:DOY';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 {
6 5 $Web::Request::Upload::VERSION = '0.11';
7 }
8 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 # ABSTRACT: class representing a file upload
10  
11 5 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use Web::Request::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 5 has headers => (
17 is => 'ro',
18 isa => 'Web::Request::Types::HTTP::Headers',
19 coerce => 1,
20 handles => ['content_type'],
21 );
22  
23 5 has tempname => (
24 is => 'ro',
25 isa => 'Str',
26 );
27  
28 5 has size => (
29 is => 'ro',
30 isa => 'Int',
31 );
32  
33 5 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 2 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
46  
47 2 require File::Spec::Unix;
48  
49 2 my $basename = $self->{filename};
50 2 $basename =~ s{\\}{/}g;
51 2 $basename = (File::Spec::Unix->splitpath($basename))[2];
52 2 $basename =~ s{[^\w\.-]+}{_}g;
53  
54 2 return $basename;
55 },
56 5 );
57  
58 5 __PACKAGE__->meta->make_immutable;
59 5 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61  
62 5 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
« Request/Types.pm ↑ Summary