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