X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FStatic%2FSimple.pm;h=a89825dedc246ca4333d98bb4023eae33102f707;hp=d432f5fe1c544fdb3ca6a1c2e5479b8ae7f3a3af;hb=04e5fb839ae776b17d6409f728cf3f0e1eb4c795;hpb=6e692ab40044cb1913d68d56196ce2c9dee45c9c diff --git a/lib/Catalyst/Plugin/Static/Simple.pm b/lib/Catalyst/Plugin/Static/Simple.pm index d432f5f..a89825d 100644 --- a/lib/Catalyst/Plugin/Static/Simple.pm +++ b/lib/Catalyst/Plugin/Static/Simple.pm @@ -4,6 +4,7 @@ use strict; use warnings; use base qw/Class::Accessor::Fast Class::Data::Inheritable/; use File::stat; +use IO::File; use MIME::Types; use NEXT; @@ -11,7 +12,7 @@ if ( Catalyst->VERSION le '5.33' ) { require File::Slurp; } -our $VERSION = '0.10'; +our $VERSION = '0.11'; __PACKAGE__->mk_classdata( qw/_static_mime_types/ ); __PACKAGE__->mk_accessors( qw/_static_file @@ -191,17 +192,18 @@ sub _serve_static { if ( Catalyst->VERSION le '5.33' ) { # old File::Slurp method my $content = File::Slurp::read_file( $full_path ); - $c->res->output( $content ); + $c->res->body( $content ); } else { - # new write method - open my $fh, '<', $full_path - or Catalyst::Exception->throw( + # new method, pass an IO::File object to body + my $fh = IO::File->new( $full_path, 'r' ); + if ( defined $fh ) { + $c->res->body( $fh ); + } + else { + Catalyst::Exception->throw( message => "Unable to open $full_path for reading" ); - while ( $fh->read( my $buffer, 4096 ) ) { - $c->res->write( $buffer ); } - close $fh; } return 1; @@ -220,7 +222,7 @@ sub _ext_to_type { if ( $type ) { $c->_debug_msg( "as $type" ) if ( $c->config->{static}->{debug} ); - return $type; + return ( ref $type ) ? $type->type : $type; } else { $c->_debug_msg( "as text/plain (unknown extension $ext)" )