[Jifty-commit] r7658 - jifty/trunk/lib/Jifty/Web

Jifty commits jifty-commit at lists.jifty.org
Thu Nov 19 16:00:06 EST 2009


Author: sartak
Date: Thu Nov 19 16:00:03 2009
New Revision: 7658

Modified:
   jifty/trunk/lib/Jifty/Web/FileUpload.pm

Log:
Don't read in the FileUpload's content immediately. Only slurp it on demand to avoid breaking compat

Modified: jifty/trunk/lib/Jifty/Web/FileUpload.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/FileUpload.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/FileUpload.pm	Thu Nov 19 16:00:03 2009
@@ -3,7 +3,7 @@
 use warnings;
 use base qw/Jifty::Object Class::Accessor::Fast/;
 
-__PACKAGE__->mk_accessors(qw(filehandle content filename content_type));
+__PACKAGE__->mk_accessors(qw(filehandle _content filename content_type));
 
 use overload (
     q{""} => sub { $_[0]->filename },
@@ -69,12 +69,6 @@
     ref($fh) eq 'Fh'
         or die "The filehandle must be an Fh object produced by CGI";
 
-    if (!defined($args{content})) {
-        binmode $fh;
-        local $/;
-        $args{content} = <$fh>;
-    }
-
     if (!defined($args{filename})) {
         $args{filename} = "$fh";
     }
@@ -92,6 +86,29 @@
     return $self;
 }
 
+=head2 content
+
+Lazily slurps in the filehandle's content.
+
+=cut
+
+sub content {
+    my $self = shift;
+    if (@_) {
+        return $self->_content(@_);
+    }
+
+    my $content = $self->_content;
+    if (!defined($content)) {
+        my $fh = $self->filehandle;;
+        local $/;
+        $content = <$fh>;
+        $self->_content($content);
+    }
+
+    return $content;
+}
+
 =head2 new_from_fh Fh
 
 Convenience method, since the other bits can be gleaned from the L<Fh> object.


More information about the Jifty-commit mailing list