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