Commit | Line | Data |
146554c5 |
1 | package Catalyst::Request::Upload; |
2 | |
3 | use strict; |
4 | use base 'Class::Accessor::Fast'; |
5 | |
47ae6960 |
6 | use File::Copy (); |
7 | use IO::File (); |
146554c5 |
8 | |
9 | __PACKAGE__->mk_accessors(qw/filename size tempname type/); |
10 | |
146554c5 |
11 | |
12 | =head1 NAME |
13 | |
14 | Catalyst::Request::Upload - Catalyst Request Upload Class |
15 | |
16 | =head1 SYNOPSIS |
17 | |
3ffaf022 |
18 | $upload->copy_to |
146554c5 |
19 | $upload->fh |
20 | $upload->filename; |
3ffaf022 |
21 | $upload->link_to; |
146554c5 |
22 | $upload->size; |
23 | $upload->tempname; |
24 | $upload->type; |
25 | |
26 | See also L<Catalyst>. |
27 | |
28 | =head1 DESCRIPTION |
29 | |
47ae6960 |
30 | This is the Catalyst Request Upload class, which provides a set of accessors |
31 | to the upload data. |
146554c5 |
32 | |
33 | =head1 METHODS |
34 | |
35 | =over 4 |
36 | |
c539a1c3 |
37 | =item $upload->new |
38 | |
39 | Constructor. Normally only for engine use. |
40 | |
41 | =cut |
42 | |
43 | sub new { shift->SUPER::new( ref( $_[0] ) ? $_[0] : {@_} ) } |
44 | |
3ffaf022 |
45 | =item $upload->copy_to |
47ae6960 |
46 | |
47 | Copies tempname using C<File::Copy>. Returns true for success, false otherwise. |
48 | |
3ffaf022 |
49 | $upload->copy_to('/path/to/target'); |
50 | |
47ae6960 |
51 | =cut |
52 | |
3ffaf022 |
53 | sub copy_to { |
c462faf0 |
54 | my $self = shift; |
55 | return File::Copy::copy( $self->tempname, @_ ); |
47ae6960 |
56 | } |
57 | |
146554c5 |
58 | =item $upload->fh |
59 | |
60 | Opens tempname and returns a C<IO::File> handle. |
61 | |
62 | =cut |
63 | |
64 | sub fh { |
65 | my $self = shift; |
66 | |
47ae6960 |
67 | my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY ) |
146554c5 |
68 | or die( "Can't open ", $self->tempname, ": ", $! ); |
69 | |
70 | return $fh; |
71 | } |
72 | |
73 | =item $upload->filename |
74 | |
75 | Contains client supplied filename. |
76 | |
3ffaf022 |
77 | =item $upload->link_to |
146554c5 |
78 | |
3ffaf022 |
79 | Creates a hard link to the tempname. Returns true for success, |
80 | false otherwise. |
146554c5 |
81 | |
3ffaf022 |
82 | $upload->link_to('/path/to/target'); |
146554c5 |
83 | |
84 | =cut |
85 | |
3ffaf022 |
86 | sub link_to { |
47ae6960 |
87 | my ( $self, $target ) = @_; |
5c0ff128 |
88 | return CORE::link( $self->tempname, $target ); |
146554c5 |
89 | } |
90 | |
91 | =item $upload->size |
92 | |
93 | Contains size of the file in bytes. |
94 | |
95 | =item $upload->tempname |
96 | |
97 | Contains path to the temporary spool file. |
98 | |
99 | =item $upload->type |
100 | |
101 | Contains client supplied Content-Type. |
102 | |
103 | =back |
104 | |
105 | =head1 AUTHOR |
106 | |
107 | Sebastian Riedel, C<sri@cpan.org> |
108 | Christian Hansen, C<ch@ngmedia.com> |
109 | |
110 | =head1 COPYRIGHT |
111 | |
112 | This program is free software, you can redistribute it and/or modify |
113 | it under the same terms as Perl itself. |
114 | |
115 | =cut |
116 | |
117 | 1; |