fixed makefile
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request / Upload.pm
index 2cd3eb9..867c098 100644 (file)
@@ -3,7 +3,8 @@ package Catalyst::Request::Upload;
 use strict;
 use base 'Class::Accessor::Fast';
 
-use IO::File;
+use File::Copy ();
+use IO::File   ();
 
 __PACKAGE__->mk_accessors(qw/filename size tempname type/);
 
@@ -15,9 +16,10 @@ Catalyst::Request::Upload - Catalyst Request Upload Class
 
 =head1 SYNOPSIS
 
+    $upload->copy_to
     $upload->fh
     $upload->filename;
-    $upload->link;
+    $upload->link_to;
     $upload->size;
     $upload->tempname;
     $upload->type;
@@ -26,13 +28,26 @@ See also L<Catalyst>.
 
 =head1 DESCRIPTION
 
-This is the Catalyst Request Upload class, which provides a set of accessors to the
-upload data.
+This is the Catalyst Request Upload class, which provides a set of accessors 
+to the upload data.
 
 =head1 METHODS
 
 =over 4
 
+=item $upload->copy_to
+
+Copies tempname using C<File::Copy>. Returns true for success, false otherwise.
+
+     $upload->copy_to('/path/to/target');
+
+=cut
+
+sub copy_to {
+    my ( $self, $target, $buffer ) = @_;
+    return File::Copy::copy( $self->tempname, $target, $buffer );
+}
+
 =item $upload->fh
 
 Opens tempname and returns a C<IO::File> handle.
@@ -42,7 +57,7 @@ Opens tempname and returns a C<IO::File> handle.
 sub fh {
     my $self = shift;
 
-    my $fh = IO::File->new( $self->tempname, O_RDONLY )
+    my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY )
       or die( "Can't open ", $self->tempname, ": ", $! );
 
     return $fh;
@@ -52,20 +67,18 @@ sub fh {
 
 Contains client supplied filename.
 
-=item $upload->link
+=item $upload->link_to
 
-Creates a new filename linked to the old filename.  Returns true for
-success, false otherwise.
+Creates a hard link to the tempname.  Returns true for success, 
+false otherwise.
 
-    $upload->link('/my/path');
+    $upload->link_to('/path/to/target');
 
 =cut
 
-sub link {
-    my $self   = shift;
-    my $target = shift;
-
-    return link( $self->tempname, $target );
+sub link_to {
+    my ( $self, $target ) = @_;
+    return CORE::link( $self->tempname, $target );
 }
 
 =item $upload->size