1 package Catalyst::Request::Upload;
4 use base 'Class::Accessor::Fast';
6 use Catalyst::Exception;
10 __PACKAGE__->mk_accessors(qw/filename headers size tempname type/);
12 sub new { shift->SUPER::new( ref( $_[0] ) ? $_[0] : {@_} ) }
16 Catalyst::Request::Upload - Catalyst Request Upload Class
34 This is the Catalyst Request Upload class, which provides a set of accessors
45 =item $upload->copy_to
47 Copies tempname using C<File::Copy>. Returns true for success, false otherwise.
49 $upload->copy_to('/path/to/target');
55 return File::Copy::copy( $self->tempname, @_ );
60 Opens tempname and returns a C<IO::File> handle.
67 my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY );
69 unless ( defined $fh ) {
71 my $filename = $self->tempname;
73 Catalyst::Exception->throw(
74 message => qq/Can't open '$filename': '$!'/ );
80 =item $upload->filename
82 Contains client supplied filename.
84 =item $upload->headers
86 Returns a C<HTTP::Headers> object.
88 =item $upload->link_to
90 Creates a hard link to the tempname. Returns true for success,
93 $upload->link_to('/path/to/target');
98 my ( $self, $target ) = @_;
99 return CORE::link( $self->tempname, $target );
104 Contains size of the file in bytes.
108 Returns a scalar containing contents of tempname.
113 my ( $self, $layer ) = @_;
120 my $handle = $self->fh;
122 binmode( $handle, $layer );
124 while ( $handle->sysread( my $buffer, 8192 ) ) {
131 =item $upload->tempname
133 Contains path to the temporary spool file.
137 Contains client supplied Content-Type.
143 Sebastian Riedel, C<sri@cpan.org>
144 Christian Hansen, C<ch@ngmedia.com>
148 This program is free software, you can redistribute it and/or modify
149 it under the same terms as Perl itself.