Newer Older
100 lines | 1.747kb
add files
Yuki Kimoto authored on 2014-03-26
1
package Mojo::Upload;
2
use Mojo::Base -base;
3

            
4
use Mojo::Asset::File;
5
use Mojo::Headers;
6

            
7
has asset => sub { Mojo::Asset::File->new };
8
has [qw(filename name)];
9
has headers => sub { Mojo::Headers->new };
10

            
11
sub move_to {
12
  my $self = shift;
13
  $self->asset->move_to(@_);
14
  return $self;
15
}
16

            
17
sub size  { shift->asset->size }
18
sub slurp { shift->asset->slurp }
19

            
20
1;
21

            
22
=encoding utf8
23

            
24
=head1 NAME
25

            
26
Mojo::Upload - Upload
27

            
28
=head1 SYNOPSIS
29

            
30
  use Mojo::Upload;
31

            
32
  my $upload = Mojo::Upload->new;
33
  say $upload->filename;
34
  $upload->move_to('/home/sri/foo.txt');
35

            
36
=head1 DESCRIPTION
37

            
38
L<Mojo::Upload> is a container for uploaded files.
39

            
40
=head1 ATTRIBUTES
41

            
42
L<Mojo::Upload> implements the following attributes.
43

            
44
=head2 asset
45

            
46
  my $asset = $upload->asset;
47
  $upload   = $upload->asset(Mojo::Asset::File->new);
48

            
49
Asset containing the uploaded data, usually a L<Mojo::Asset::File> or
50
L<Mojo::Asset::Memory> object.
51

            
52
=head2 filename
53

            
54
  my $filename = $upload->filename;
55
  $upload      = $upload->filename('foo.txt');
56

            
57
Name of the uploaded file.
58

            
59
=head2 headers
60

            
61
  my $headers = $upload->headers;
62
  $upload     = $upload->headers(Mojo::Headers->new);
63

            
64
Headers for upload, defaults to a L<Mojo::Headers> object.
65

            
66
=head2 name
67

            
68
  my $name = $upload->name;
69
  $upload  = $upload->name('foo');
70

            
71
Name of the upload.
72

            
73
=head1 METHODS
74

            
75
L<Mojo::Upload> inherits all methods from L<Mojo::Base> and implements the
76
following new ones.
77

            
78
=head2 move_to
79

            
80
  $upload = $upload->move_to('/home/sri/foo.txt');
81

            
82
Move uploaded data into a specific file.
83

            
84
=head2 size
85

            
86
  my $size = $upload->size;
87

            
88
Size of uploaded data in bytes.
89

            
90
=head2 slurp
91

            
92
  my $bytes = $upload->slurp;
93

            
94
Read all uploaded data at once.
95

            
96
=head1 SEE ALSO
97

            
98
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
99

            
100
=cut