Change configuration key to 'Plugin::Static::Simple' by default.
Alexander Hartmaier [Fri, 4 May 2012 17:01:26 +0000 (17:01 +0000)]
The old 'static' key is still supported, but issues a warning.

Changes
lib/Catalyst/Plugin/Static/Simple.pm
t/04static.t
t/05dirs.t
t/06include_path.t
t/07mime_types.t
t/08subreq.t
t/10ignore_dirs.t
t/12check_error_scope.t
t/20debug.t

diff --git a/Changes b/Changes
index 71d2367..641903e 100644 (file)
--- a/Changes
+++ b/Changes
@@ -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
index 91cef4a..1611f93 100644 (file)
@@ -6,6 +6,7 @@ use File::Spec ();
 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 @@ has _static_debug_message => ( is => 'rw', isa => ArrayRef[Str] );
 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 @@ around dispatch => sub {
     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 @@ before finalize => sub {
     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 finalize => sub {
 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 @@ sub _locate_static_file {
         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 _locate_static_file {
 
 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 {
 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 serve_static_file {
 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;
index bae2922..b301341 100644 (file)
@@ -1,37 +1,37 @@
-#!perl\r
-\r
-use strict;\r
-use warnings;\r
-\r
-use FindBin;\r
-use lib "$FindBin::Bin/lib";\r
-\r
-# Module::Build craps out on files with spaces so it's not included in the dist\r
-my $has_space_file = -e "$FindBin::Bin/lib/TestApp/root/files/space file.txt";\r
-\r
-use Test::More;\r
+#!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';\r
-\r
-# test getting a css file\r
-ok( my $res = request('http://localhost/files/static.css'), 'request ok' );\r
-is( $res->content_type, 'text/css', 'content-type text/css ok' );\r
-like( $res->content, qr/background/, 'content of css ok' );\r
-\r
-# test a file with spaces\r
-if ( $has_space_file ) {\r
-    ok( $res = request('http://localhost/files/space file.txt'), 'request ok' );\r
-    is( $res->content_type, 'text/plain', 'content-type text/plain ok' );\r
-    like( $res->content, qr/background/, 'content of space file ok' );\r
-}\r
-\r
-# test a non-existent file\r
-ok( $res = request('http://localhost/files/404.txt'), 'request ok' );\r
-is( $res->content, 'default', 'default handler for non-existent content ok' );\r
-\r
-# test unknown extension\r
-ok( $res = request('http://localhost/files/err.omg'), 'request ok' );\r
-is( $res->content_type, 'text/plain', 'unknown extension as text/plain ok' );\r
+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' );
index acb299e..f342556 100644 (file)
@@ -1,42 +1,42 @@
-#!perl\r
-\r
-use strict;\r
-use warnings;\r
-\r
-use FindBin;\r
-use lib "$FindBin::Bin/lib";\r
-\r
-use Test::More tests => 13;\r
-use Catalyst::Test 'TestApp';\r
-\r
-# test defined static dirs\r
-TestApp->config->{static}->{dirs} = [\r
-    'always-static',\r
-    qr/^images/,\r
-    'qr/^css/',\r
-];\r
-\r
-# a file with no extension will return text/plain\r
-ok( my $res = request('http://localhost/always-static/test'), 'request ok' );\r
-is( $res->content_type, 'text/plain', 'text/plain ok' );\r
-\r
-# a file with an extension in ignore_extensions still gets served\r
-ok( $res = request('http://localhost/always-static/test.html'), 'request ok' );\r
-is( $res->code, 200, 'html file in dirs get served' );\r
-\r
-# a missing file in a defined static dir will return 404 and text/html\r
-ok( $res = request('http://localhost/always-static/404.txt'), 'request ok' );\r
-is( $res->code, 404, '404 ok' );\r
-is( $res->content_type, 'text/html', '404 is text/html' );\r
-\r
-# qr regex test\r
-ok( $res = request('http://localhost/images/catalyst.png'), 'request ok' );\r
-is( $res->content_type, 'image/png', 'qr regex path ok' );\r
-\r
-# eval regex test\r
-ok( $res = request('http://localhost/css/static.css'), 'request ok' );\r
-like( $res->content, qr/background/, 'eval regex path ok' );\r
-\r
-# A static dir with no trailing slash is handled by Cat\r
-ok( $res = request('http://localhost/always-static'), 'request ok' );\r
-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' );
index 144f39a..b0d2d26 100644 (file)
@@ -1,29 +1,29 @@
-#!perl\r
-\r
-use strict;\r
-use warnings;\r
-\r
-use FindBin;\r
-use lib "$FindBin::Bin/lib";\r
-\r
-use Test::More tests => 6;\r
-use Catalyst::Test 'TestApp';\r
-\r
-# test altenate root dirs\r
-TestApp->config->{static}->{include_path} = [\r
-    TestApp->config->{root} . '/overlay',\r
-    \&TestApp::incpath_generator,\r
-    TestApp->config->{root},\r
-];\r
-\r
-# test overlay dir\r
-ok( my $res = request('http://localhost/overlay.jpg'), 'request ok' );\r
-is( $res->content_type, 'image/jpeg', 'overlay path ok' );\r
-\r
-# test incpath_generator\r
-ok( $res = request('http://localhost/incpath.css'), 'request ok' );\r
-is( $res->content_type, 'text/css', 'incpath coderef ok' );\r
-\r
-# test passthrough to root\r
-ok( $res = request('http://localhost/images/bad.gif'), 'request ok' );\r
-is( $res->content_type, 'image/gif', 'root path ok' );\r
+#!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' );
index 4652494..e9276b0 100644 (file)
@@ -10,7 +10,7 @@ use Test::More tests => 4;
 use Catalyst::Test 'TestApp';\r
 \r
 # test custom MIME types\r
-TestApp->config->{static}->{mime_types} = {\r
+TestApp->config->{'Plugin::Static::Simple'}->{mime_types} = {\r
     omg => 'holy/crap',\r
     gif => 'patents/are-evil',\r
 };\r
index 911bf5c..e5be28d 100644 (file)
@@ -1,24 +1,24 @@
-#!perl\r
-\r
-use strict;\r
-use warnings;\r
-\r
-use FindBin;\r
-use lib "$FindBin::Bin/lib";\r
-\r
-use Test::More tests => 2;\r
-use Catalyst::Test 'TestApp';\r
-\r
-SKIP:\r
-{\r
-    unless ( TestApp->isa('Catalyst::Plugin::SubRequest') ) {\r
-        skip "Install Catalyst::Plugin::SubRequest >= 0.15 for these tests", 2;\r
-    }\r
-    unless ( $Catalyst::Plugin::SubRequest::VERSION >= 0.15 ) {\r
-        skip "Need Catalyst::Plugin::SubRequest >= 0.15 for these tests", 2;\r
-    }\r
-\r
-    ok( my $res = request('http://localhost/subtest'), 'Request' );\r
-    is( $res->content, 'subtest2 ok', 'SubRequest ok' );\r
-}\r
-\r
+#!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' );
+}
+
index ba80c03..01cdc14 100644 (file)
@@ -10,10 +10,10 @@ use Test::More tests => 6;
 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},
 ];
index 14a7655..fc67c29 100644 (file)
@@ -23,7 +23,7 @@ BEGIN {
 }
 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} );
index e934dee..400dfcd 100644 (file)
@@ -1,38 +1,38 @@
-#!perl\r
-\r
-use strict;\r
-use warnings;\r
-\r
-use FindBin;\r
-use lib "$FindBin::Bin/lib";\r
-\r
-use Test::More tests => 5;\r
-use Catalyst::Test 'TestApp';\r
-\r
-# test defined static dirs\r
-TestApp->config->{static}->{dirs} = [\r
-    'always-static',\r
-];\r
-\r
-TestApp->config->{static}->{debug} = 1;\r
-\r
-use Catalyst::Log;\r
-\r
-local *Catalyst::Log::_send_to_log;\r
-local our @MESSAGES;\r
-{\r
-    no warnings 'redefine';\r
-    *Catalyst::Log::_send_to_log = sub {\r
-        my $self = shift;\r
-        push @MESSAGES, @_;\r
-    };\r
-}\r
-\r
-\r
-# a missing file in a defined static dir will return 404 and text/html\r
-ok( my $res = request('http://localhost/always-static/404.txt'), 'request ok' );\r
-is( $res->code, 404, '404 ok' );\r
-is( $res->content_type, 'text/html', '404 is text/html' );\r
-ok(defined $MESSAGES[0], 'debug message set');\r
-like( $MESSAGES[0], qr/404/, 'debug message contains 404'); \r
-\r
+#!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');
+