FAQ
---
I noticed that calling slurp on a Catalyst::Request::Upload object twice
returns an empty string the second time.

I tried to modify t/aggregate/live_engine_request_uploads.t to add a
failing test, but if I call slurp() there, I get an error about the
temporary file missing.

So this crude change below, just calling slurp() twice, makes existing
tests fail, instead.

t/lib/TestApp/Controller/Engine/Request/Uploads.pm | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/t/lib/TestApp/Controller/Engine/Request/Uploads.pm b/t/lib/TestApp/Controller/Engine/Request/Uploads.pm
index f51df9d..7ebcd65 100644
--- a/t/lib/TestApp/Controller/Engine/Request/Uploads.pm
+++ b/t/lib/TestApp/Controller/Engine/Request/Uploads.pm
@@ -6,6 +6,7 @@ use base 'Catalyst::Controller';
sub slurp : Relative {
my ( $self, $c ) = @_;
$c->response->content_type('text/plain; charset=utf-8');
+ $c->request->upload('slurp')->slurp;
$c->response->output( $c->request->upload('slurp')->slurp );
}

--
1.7.2.3

Search Discussions

  • Adam Sjøgren at Feb 15, 2011 at 3:38 pm
    ---
    lib/Catalyst/Request/Upload.pm | 7 ++++++-
    1 files changed, 6 insertions(+), 1 deletions(-)

    diff --git a/lib/Catalyst/Request/Upload.pm b/lib/Catalyst/Request/Upload.pm
    index aee3625..bf048b1 100644
    --- a/lib/Catalyst/Request/Upload.pm
    +++ b/lib/Catalyst/Request/Upload.pm
    @@ -5,7 +5,7 @@ with 'MooseX::Emulate::Class::Accessor::Fast';

    use Catalyst::Exception;
    use File::Copy ();
    -use IO::File ();
    +use IO::File qw(SEEK_SET);
    use File::Spec::Unix;

    has filename => (is => 'rw');
    @@ -142,10 +142,15 @@ sub slurp {

    binmode( $handle, $layer );

    + my $prevpos = $handle->getpos;
    +
    + $handle->seek(0, SEEK_SET);
    while ( $handle->sysread( my $buffer, 8192 ) ) {
    $content .= $buffer;
    }

    + $handle->setpos($prevpos);
    +
    return $content;
    }

    --
    1.7.2.3

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedFeb 15, '11 at 3:35p
activeFeb 15, '11 at 3:38p
posts2
users1
websitecatalystframework.org
irc#catalyst

1 user in discussion

Adam Sjøgren: 2 posts

People

Translate

site design / logo © 2022 Grokbase