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