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