[Catalyst-commits] r14286 - in Catalyst-Plugin-Static-Simple/trunk: . lib/Catalyst/Plugin/Static t

abraxxa at dev.catalyst.perl.org abraxxa at dev.catalyst.perl.org
Fri May 4 17:01:26 GMT 2012


Author: abraxxa
Date: 2012-05-04 17:01:26 +0000 (Fri, 04 May 2012)
New Revision: 14286

Modified:
   Catalyst-Plugin-Static-Simple/trunk/Changes
   Catalyst-Plugin-Static-Simple/trunk/lib/Catalyst/Plugin/Static/Simple.pm
   Catalyst-Plugin-Static-Simple/trunk/t/04static.t
   Catalyst-Plugin-Static-Simple/trunk/t/05dirs.t
   Catalyst-Plugin-Static-Simple/trunk/t/06include_path.t
   Catalyst-Plugin-Static-Simple/trunk/t/07mime_types.t
   Catalyst-Plugin-Static-Simple/trunk/t/08subreq.t
   Catalyst-Plugin-Static-Simple/trunk/t/10ignore_dirs.t
   Catalyst-Plugin-Static-Simple/trunk/t/12check_error_scope.t
   Catalyst-Plugin-Static-Simple/trunk/t/20debug.t
Log:
Change configuration key to 'Plugin::Static::Simple' by default.

The old 'static' key is still supported, but issues a warning.

Modified: Catalyst-Plugin-Static-Simple/trunk/Changes
===================================================================
--- Catalyst-Plugin-Static-Simple/trunk/Changes	2012-04-27 07:40:14 UTC (rev 14285)
+++ Catalyst-Plugin-Static-Simple/trunk/Changes	2012-05-04 17:01:26 UTC (rev 14286)
@@ -1,5 +1,8 @@
 Revision history for Perl extension Catalyst::Plugin::Static::Simple
 
+        - Change configuration key to 'Plugin::Static::Simple' by default.
+          The old 'static' key is still supported, but issues a warning.
+
 0.30   2011-02-xx hh:mm:00
         - Add Cache-Control:public header
         - Optionally provide Expires header

Modified: Catalyst-Plugin-Static-Simple/trunk/lib/Catalyst/Plugin/Static/Simple.pm
===================================================================
--- Catalyst-Plugin-Static-Simple/trunk/lib/Catalyst/Plugin/Static/Simple.pm	2012-04-27 07:40:14 UTC (rev 14285)
+++ Catalyst-Plugin-Static-Simple/trunk/lib/Catalyst/Plugin/Static/Simple.pm	2012-05-04 17:01:26 UTC (rev 14286)
@@ -6,6 +6,7 @@
 use IO::File ();
 use MIME::Types ();
 use MooseX::Types::Moose qw/ArrayRef Str/;
+use Catalyst::Utils;
 use namespace::autoclean;
 
 our $VERSION = '0.30';
@@ -16,7 +17,7 @@
 before prepare_action => sub {
     my $c = shift;
     my $path = $c->req->path;
-    my $config = $c->config->{static};
+    my $config = $c->config->{'Plugin::Static::Simple'};
 
     $path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
 
@@ -67,7 +68,7 @@
     return if ( $c->res->status != 200 );
 
     if ( $c->_static_file ) {
-        if ( $c->config->{static}{no_logs} && $c->log->can('abort') ) {
+        if ( $c->config->{'Plugin::Static::Simple'}->{no_logs} && $c->log->can('abort') ) {
            $c->log->abort( 1 );
         }
         return $c->_serve_static;
@@ -81,7 +82,7 @@
     my $c = shift;
 
     # display all log messages
-    if ( $c->config->{static}{debug} && scalar @{$c->_debug_msg} ) {
+    if ( $c->config->{'Plugin::Static::Simple'}->{debug} && scalar @{$c->_debug_msg} ) {
         $c->log->debug( 'Static::Simple: ' . join q{ }, @{$c->_debug_msg} );
     }
 };
@@ -89,7 +90,15 @@
 before setup_finalize => sub {
     my $c = shift;
 
-    my $config = $c->config->{static} ||= {};
+    $c->log->warn("Deprecated 'static' config key used, please use the key 'Plugin::Static::Simple' instead")
+        if exists $c->config->{static};
+    my $config
+        = $c->config->{'Plugin::Static::Simple'}
+        = $c->config->{'static'}
+        = Catalyst::Utils::merge_hashes(
+            $c->config->{'Plugin::Static::Simple'} || {},
+            $c->config->{static} || {}
+        );
 
     $config->{dirs} ||= [];
     $config->{include_path} ||= [ $c->config->{root} ];
@@ -117,7 +126,7 @@
         File::Spec->no_upwards( File::Spec->splitdir( $path ) )
     );
 
-    my $config = $c->config->{static};
+    my $config = $c->config->{'Plugin::Static::Simple'};
     my @ipaths = @{ $config->{include_path} };
     my $dpaths;
     my $count = 64; # maximum number of directories to search
@@ -172,7 +181,7 @@
 
 sub _serve_static {
     my $c = shift;
-    my $config = $c->config->{static} ||= {};
+    my $config = $c->config->{'Plugin::Static::Simple'};
 
     my $full_path = shift || $c->_static_file;
     my $type      = $c->_ext_to_type( $full_path );
@@ -204,7 +213,7 @@
 sub serve_static_file {
     my ( $c, $full_path ) = @_;
 
-    my $config = $c->config->{static} ||= {};
+    my $config = $c->config->{'Plugin::Static::Simple'};
 
     if ( -e $full_path ) {
         $c->_debug_msg( "Serving static file: $full_path" )
@@ -225,7 +234,7 @@
 sub _ext_to_type {
     my ( $c, $full_path ) = @_;
 
-    my $config = $c->config->{static};
+    my $config = $c->config->{'Plugin::Static::Simple'};
 
     if ( $full_path =~ /.*\.(\S{1,})$/xms ) {
         my $ext = $1;

Modified: Catalyst-Plugin-Static-Simple/trunk/t/04static.t
===================================================================
--- Catalyst-Plugin-Static-Simple/trunk/t/04static.t	2012-04-27 07:40:14 UTC (rev 14285)
+++ Catalyst-Plugin-Static-Simple/trunk/t/04static.t	2012-05-04 17:01:26 UTC (rev 14286)
@@ -1,37 +1,37 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-
-# Module::Build craps out on files with spaces so it's not included in the dist
-my $has_space_file = -e "$FindBin::Bin/lib/TestApp/root/files/space file.txt";
-
-use Test::More;
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+# Module::Build craps out on files with spaces so it's not included in the dist
+my $has_space_file = -e "$FindBin::Bin/lib/TestApp/root/files/space file.txt";
+
+use Test::More;
 plan tests => ($has_space_file) ? 12 : 9;
-use Catalyst::Test 'TestApp';
-
-# test getting a css file
-ok( my $res = request('http://localhost/files/static.css'), 'request ok' );
-is( $res->content_type, 'text/css', 'content-type text/css ok' );
-like( $res->content, qr/background/, 'content of css ok' );
-
-# test a file with spaces
-if ( $has_space_file ) {
-    ok( $res = request('http://localhost/files/space file.txt'), 'request ok' );
-    is( $res->content_type, 'text/plain', 'content-type text/plain ok' );
-    like( $res->content, qr/background/, 'content of space file ok' );
-}
-
-# test a non-existent file
-ok( $res = request('http://localhost/files/404.txt'), 'request ok' );
-is( $res->content, 'default', 'default handler for non-existent content ok' );
-
-# test unknown extension
-ok( $res = request('http://localhost/files/err.omg'), 'request ok' );
-is( $res->content_type, 'text/plain', 'unknown extension as text/plain ok' );
+use Catalyst::Test 'TestApp';
 
+# test getting a css file
+ok( my $res = request('http://localhost/files/static.css'), 'request ok' );
+is( $res->content_type, 'text/css', 'content-type text/css ok' );
+like( $res->content, qr/background/, 'content of css ok' );
+
+# test a file with spaces
+if ( $has_space_file ) {
+    ok( $res = request('http://localhost/files/space file.txt'), 'request ok' );
+    is( $res->content_type, 'text/plain', 'content-type text/plain ok' );
+    like( $res->content, qr/background/, 'content of space file ok' );
+}
+
+# test a non-existent file
+ok( $res = request('http://localhost/files/404.txt'), 'request ok' );
+is( $res->content, 'default', 'default handler for non-existent content ok' );
+
+# test unknown extension
+ok( $res = request('http://localhost/files/err.omg'), 'request ok' );
+is( $res->content_type, 'text/plain', 'unknown extension as text/plain ok' );
+
 ok( $res = request('http://localhost/files/empty.txt'), 'request ok' );
 is( $res->content, '', 'empty files result in an empty response' );

Modified: Catalyst-Plugin-Static-Simple/trunk/t/05dirs.t
===================================================================
--- Catalyst-Plugin-Static-Simple/trunk/t/05dirs.t	2012-04-27 07:40:14 UTC (rev 14285)
+++ Catalyst-Plugin-Static-Simple/trunk/t/05dirs.t	2012-05-04 17:01:26 UTC (rev 14286)
@@ -1,42 +1,42 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-
-use Test::More tests => 13;
-use Catalyst::Test 'TestApp';
-
-# test defined static dirs
-TestApp->config->{static}->{dirs} = [
-    'always-static',
-    qr/^images/,
-    'qr/^css/',
-];
-
-# a file with no extension will return text/plain
-ok( my $res = request('http://localhost/always-static/test'), 'request ok' );
-is( $res->content_type, 'text/plain', 'text/plain ok' );
-
-# a file with an extension in ignore_extensions still gets served
-ok( $res = request('http://localhost/always-static/test.html'), 'request ok' );
-is( $res->code, 200, 'html file in dirs get served' );
-
-# a missing file in a defined static dir will return 404 and text/html
-ok( $res = request('http://localhost/always-static/404.txt'), 'request ok' );
-is( $res->code, 404, '404 ok' );
-is( $res->content_type, 'text/html', '404 is text/html' );
-
-# qr regex test
-ok( $res = request('http://localhost/images/catalyst.png'), 'request ok' );
-is( $res->content_type, 'image/png', 'qr regex path ok' );
-
-# eval regex test
-ok( $res = request('http://localhost/css/static.css'), 'request ok' );
-like( $res->content, qr/background/, 'eval regex path ok' );
-
-# A static dir with no trailing slash is handled by Cat
-ok( $res = request('http://localhost/always-static'), 'request ok' );
-is( $res->content, 'default', 'content ok' );
\ No newline at end of file
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More tests => 13;
+use Catalyst::Test 'TestApp';
+
+# test defined static dirs
+TestApp->config->{'Plugin::Static::Simple'}->{dirs} = [
+    'always-static',
+    qr/^images/,
+    'qr/^css/',
+];
+
+# a file with no extension will return text/plain
+ok( my $res = request('http://localhost/always-static/test'), 'request ok' );
+is( $res->content_type, 'text/plain', 'text/plain ok' );
+
+# a file with an extension in ignore_extensions still gets served
+ok( $res = request('http://localhost/always-static/test.html'), 'request ok' );
+is( $res->code, 200, 'html file in dirs get served' );
+
+# a missing file in a defined static dir will return 404 and text/html
+ok( $res = request('http://localhost/always-static/404.txt'), 'request ok' );
+is( $res->code, 404, '404 ok' );
+is( $res->content_type, 'text/html', '404 is text/html' );
+
+# qr regex test
+ok( $res = request('http://localhost/images/catalyst.png'), 'request ok' );
+is( $res->content_type, 'image/png', 'qr regex path ok' );
+
+# eval regex test
+ok( $res = request('http://localhost/css/static.css'), 'request ok' );
+like( $res->content, qr/background/, 'eval regex path ok' );
+
+# A static dir with no trailing slash is handled by Cat
+ok( $res = request('http://localhost/always-static'), 'request ok' );
+is( $res->content, 'default', 'content ok' );

Modified: Catalyst-Plugin-Static-Simple/trunk/t/06include_path.t
===================================================================
--- Catalyst-Plugin-Static-Simple/trunk/t/06include_path.t	2012-04-27 07:40:14 UTC (rev 14285)
+++ Catalyst-Plugin-Static-Simple/trunk/t/06include_path.t	2012-05-04 17:01:26 UTC (rev 14286)
@@ -1,29 +1,29 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-
-use Test::More tests => 6;
-use Catalyst::Test 'TestApp';
-
-# test altenate root dirs
-TestApp->config->{static}->{include_path} = [
-    TestApp->config->{root} . '/overlay',
-    \&TestApp::incpath_generator,
-    TestApp->config->{root},
-];
-
-# test overlay dir
-ok( my $res = request('http://localhost/overlay.jpg'), 'request ok' );
-is( $res->content_type, 'image/jpeg', 'overlay path ok' );
-
-# test incpath_generator
-ok( $res = request('http://localhost/incpath.css'), 'request ok' );
-is( $res->content_type, 'text/css', 'incpath coderef ok' );
-
-# test passthrough to root
-ok( $res = request('http://localhost/images/bad.gif'), 'request ok' );
-is( $res->content_type, 'image/gif', 'root path ok' );
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More tests => 6;
+use Catalyst::Test 'TestApp';
+
+# test altenate root dirs
+TestApp->config->{'Plugin::Static::Simple'}->{include_path} = [
+    TestApp->config->{root} . '/overlay',
+    \&TestApp::incpath_generator,
+    TestApp->config->{root},
+];
+
+# test overlay dir
+ok( my $res = request('http://localhost/overlay.jpg'), 'request ok' );
+is( $res->content_type, 'image/jpeg', 'overlay path ok' );
+
+# test incpath_generator
+ok( $res = request('http://localhost/incpath.css'), 'request ok' );
+is( $res->content_type, 'text/css', 'incpath coderef ok' );
+
+# test passthrough to root
+ok( $res = request('http://localhost/images/bad.gif'), 'request ok' );
+is( $res->content_type, 'image/gif', 'root path ok' );

Modified: Catalyst-Plugin-Static-Simple/trunk/t/07mime_types.t
===================================================================
--- Catalyst-Plugin-Static-Simple/trunk/t/07mime_types.t	2012-04-27 07:40:14 UTC (rev 14285)
+++ Catalyst-Plugin-Static-Simple/trunk/t/07mime_types.t	2012-05-04 17:01:26 UTC (rev 14286)
@@ -10,7 +10,7 @@
 use Catalyst::Test 'TestApp';
 
 # test custom MIME types
-TestApp->config->{static}->{mime_types} = {
+TestApp->config->{'Plugin::Static::Simple'}->{mime_types} = {
     omg => 'holy/crap',
     gif => 'patents/are-evil',
 };

Modified: Catalyst-Plugin-Static-Simple/trunk/t/08subreq.t
===================================================================
--- Catalyst-Plugin-Static-Simple/trunk/t/08subreq.t	2012-04-27 07:40:14 UTC (rev 14285)
+++ Catalyst-Plugin-Static-Simple/trunk/t/08subreq.t	2012-05-04 17:01:26 UTC (rev 14286)
@@ -1,24 +1,24 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-
-use Test::More tests => 2;
-use Catalyst::Test 'TestApp';
-
-SKIP:
-{
-    unless ( TestApp->isa('Catalyst::Plugin::SubRequest') ) {
-        skip "Install Catalyst::Plugin::SubRequest >= 0.15 for these tests", 2;
-    }
-    unless ( $Catalyst::Plugin::SubRequest::VERSION >= 0.15 ) {
-        skip "Need Catalyst::Plugin::SubRequest >= 0.15 for these tests", 2;
-    }
-
-    ok( my $res = request('http://localhost/subtest'), 'Request' );
-    is( $res->content, 'subtest2 ok', 'SubRequest ok' );
-}
-
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More tests => 2;
+use Catalyst::Test 'TestApp';
+
+SKIP:
+{
+    unless ( TestApp->isa('Catalyst::Plugin::SubRequest') ) {
+        skip "Install Catalyst::Plugin::SubRequest >= 0.15 for these tests", 2;
+    }
+    unless ( $Catalyst::Plugin::SubRequest::VERSION >= 0.15 ) {
+        skip "Need Catalyst::Plugin::SubRequest >= 0.15 for these tests", 2;
+    }
+
+    ok( my $res = request('http://localhost/subtest'), 'Request' );
+    is( $res->content, 'subtest2 ok', 'SubRequest ok' );
+}
+

Modified: Catalyst-Plugin-Static-Simple/trunk/t/10ignore_dirs.t
===================================================================
--- Catalyst-Plugin-Static-Simple/trunk/t/10ignore_dirs.t	2012-04-27 07:40:14 UTC (rev 14285)
+++ Catalyst-Plugin-Static-Simple/trunk/t/10ignore_dirs.t	2012-05-04 17:01:26 UTC (rev 14286)
@@ -10,10 +10,10 @@
 use Catalyst::Test 'TestApp';
 
 # test ignoring directories
-TestApp->config->{static}->{ignore_dirs} = [ qw/ignored o-ignored files/ ];
+TestApp->config->{'Plugin::Static::Simple'}->{ignore_dirs} = [ qw/ignored o-ignored files/ ];
 
 # test altenate root dirs
-TestApp->config->{static}->{include_path} = [
+TestApp->config->{'Plugin::Static::Simple'}->{include_path} = [
     TestApp->config->{root} . '/overlay',
     TestApp->config->{root},
 ];

Modified: Catalyst-Plugin-Static-Simple/trunk/t/12check_error_scope.t
===================================================================
--- Catalyst-Plugin-Static-Simple/trunk/t/12check_error_scope.t	2012-04-27 07:40:14 UTC (rev 14285)
+++ Catalyst-Plugin-Static-Simple/trunk/t/12check_error_scope.t	2012-05-04 17:01:26 UTC (rev 14286)
@@ -23,7 +23,7 @@
 }
 use Catalyst::Test 'TestApp';
 
-TestApp->config->{static}->{dirs} = [qr{stuff/}];
+TestApp->config->{'Plugin::Static::Simple'}->{dirs} = [qr{stuff/}];
 
 ok( my $res = request("http://localhost/"), 'request ok' );
 ok( $res->code == 200, q{Previous error doesn't crash static::simple} );

Modified: Catalyst-Plugin-Static-Simple/trunk/t/20debug.t
===================================================================
--- Catalyst-Plugin-Static-Simple/trunk/t/20debug.t	2012-04-27 07:40:14 UTC (rev 14285)
+++ Catalyst-Plugin-Static-Simple/trunk/t/20debug.t	2012-05-04 17:01:26 UTC (rev 14286)
@@ -1,38 +1,38 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-
-use Test::More tests => 5;
-use Catalyst::Test 'TestApp';
-
-# test defined static dirs
-TestApp->config->{static}->{dirs} = [
-    'always-static',
-];
-
-TestApp->config->{static}->{debug} = 1;
-
-use Catalyst::Log;
-
-local *Catalyst::Log::_send_to_log;
-local our @MESSAGES;
-{
-    no warnings 'redefine';
-    *Catalyst::Log::_send_to_log = sub {
-        my $self = shift;
-        push @MESSAGES, @_;
-    };
-}
-
-
-# a missing file in a defined static dir will return 404 and text/html
-ok( my $res = request('http://localhost/always-static/404.txt'), 'request ok' );
-is( $res->code, 404, '404 ok' );
-is( $res->content_type, 'text/html', '404 is text/html' );
-ok(defined $MESSAGES[0], 'debug message set');
-like( $MESSAGES[0], qr/404/, 'debug message contains 404'); 
-
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More tests => 5;
+use Catalyst::Test 'TestApp';
+
+# test defined static dirs
+TestApp->config->{'Plugin::Static::Simple'}->{dirs} = [
+    'always-static',
+];
+
+TestApp->config->{'Plugin::Static::Simple'}->{debug} = 1;
+
+use Catalyst::Log;
+
+local *Catalyst::Log::_send_to_log;
+local our @MESSAGES;
+{
+    no warnings 'redefine';
+    *Catalyst::Log::_send_to_log = sub {
+        my $self = shift;
+        push @MESSAGES, @_;
+    };
+}
+
+
+# a missing file in a defined static dir will return 404 and text/html
+ok( my $res = request('http://localhost/always-static/404.txt'), 'request ok' );
+is( $res->code, 404, '404 ok' );
+is( $res->content_type, 'text/html', '404 is text/html' );
+ok(defined $MESSAGES[0], 'debug message set');
+like( $MESSAGES[0], qr/404/, 'debug message contains 404');
+




More information about the Catalyst-commits mailing list