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