Added Catalyst::Exception
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request / Upload.pm
index a31df3d..ff0b5de 100644 (file)
@@ -3,11 +3,13 @@ package Catalyst::Request::Upload;
 use strict;
 use base 'Class::Accessor::Fast';
 
+use Catalyst::Exception;
 use File::Copy ();
 use IO::File   ();
 
 __PACKAGE__->mk_accessors(qw/filename size tempname type/);
 
+sub new { shift->SUPER::new( ref( $_[0] ) ? $_[0] : {@_} ) }
 
 =head1 NAME
 
@@ -37,11 +39,7 @@ to the upload data.
 
 =item $upload->new
 
-Constructor. Normally only for engine use.
-
-=cut 
-
-sub new { shift->SUPER::new( ref( $_[0] ) ? $_[0] : {@_} ) }
+simple constructor.
 
 =item $upload->copy_to
 
@@ -65,8 +63,16 @@ Opens tempname and returns a C<IO::File> handle.
 sub fh {
     my $self = shift;
 
-    my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY )
-      or die( "Can't open ", $self->tempname, ": ", $! );
+    my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY );
+    
+    unless ( defined $fh ) {
+        
+        my $filename = $self->tempname;
+        
+        Catalyst::Exception->throw(
+            message => qq/Can't open '$filename': '$!'/
+        );
+    }
 
     return $fh;
 }