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