Changed Static::Simple to pass an IO::File object to res->body
Andy Grundman [Thu, 20 Oct 2005 16:34:56 +0000 (16:34 +0000)]
Build.PL
Changes
META.yml
lib/Catalyst/Plugin/Static/Simple.pm

index ed4d079..36a0cde 100644 (file)
--- a/Build.PL
+++ b/Build.PL
@@ -23,7 +23,7 @@ if ( $cat->{have} le '5.33' ) {
 
 # If the user has the SubRequest plugin installed, tell them to upgrade
 my $subreq = $build->check_installed_status('Catalyst::Plugin::SubRequest');
-if ( $subreq->{have} le '0.08' ) {
+if ( $subreq->{have} lt '0.08' ) {
     print "** WARNING **\n"
         . "You appear to have a version of Catalyst::Plugin::SubRequest "
         . "older than 0.08.\n"
diff --git a/Changes b/Changes
index 7f02ca7..78caaa9 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for Perl extension Catalyst::Plugin::Static::Simple
 
+0.11    
+        - Changed 5.5 writing method to pass an IO::File object directly to
+          $c->res->body.
+
 0.10    2005-10-19 17:20:00
         - Added tt2 to the list of ignored extensions.
         - For Catalyst 5.5+, replaced File::Slurp with a buffered read/write
index 090a912..fc30e35 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,16 +1,15 @@
 ---
 name: Catalyst-Plugin-Static-Simple
-version: 0.09
+version: 0.10
 author:
   - 'Andy Grundman, <andy@hybridized.org>'
 abstract: Make serving static pages painless.
 license: perl
 requires:
   Catalyst: 5.30
-  File::Slurp: 0
   MIME::Types: 1.15
 provides:
   Catalyst::Plugin::Static::Simple:
     file: lib/Catalyst/Plugin/Static/Simple.pm
-    version: 0.09
+    version: 0.11
 generated_by: Module::Build version 0.2611
index d432f5f..a89825d 100644 (file)
@@ -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)" )