Release 0.35
[catagits/Catalyst-Plugin-Static-Simple.git] / lib / Catalyst / Plugin / Static / Simple.pm
old mode 100644 (file)
new mode 100755 (executable)
index 1611f93..f15864c
@@ -9,11 +9,20 @@ use MooseX::Types::Moose qw/ArrayRef Str/;
 use Catalyst::Utils;
 use namespace::autoclean;
 
-our $VERSION = '0.30';
+our $VERSION = '0.35';
 
 has _static_file => ( is => 'rw' );
 has _static_debug_message => ( is => 'rw', isa => ArrayRef[Str] );
 
+after setup_finalize => sub {
+  my $c = shift;
+
+  # New: Turn off new 'autoflush' flag in logger (see Catalyst::Log).
+  # This is needed to surpress output of debug log messages for 
+  # static requests:
+  $c->log->autoflush(0) if $c->log->can('autoflush');
+};
+
 before prepare_action => sub {
     my $c = shift;
     my $path = $c->req->path;
@@ -55,7 +64,7 @@ before prepare_action => sub {
     }
 
     # Does the path have an extension?
-    if ( $path =~ /.*\.(\S{1,})$/xms ) {
+    if ( $path =~ /\.([^\/\\]+)$/m ) {
         # and does it exist?
         $c->_locate_static_file( $path );
     }
@@ -92,6 +101,14 @@ before setup_finalize => sub {
 
     $c->log->warn("Deprecated 'static' config key used, please use the key 'Plugin::Static::Simple' instead")
         if exists $c->config->{static};
+
+    if (exists $c->config->{static}->{include_path}) {
+        $c->config->{'Plugin::Static::Simple'}->{include_path} = [
+            @{$c->config->{'Plugin::Static::Simple'}->{include_path} || []},
+            @{delete $c->config->{static}->{include_path} || []}
+        ];
+    }
+    
     my $config
         = $c->config->{'Plugin::Static::Simple'}
         = $c->config->{'static'}
@@ -112,9 +129,6 @@ before setup_finalize => sub {
     # load up a MIME::Types object, only loading types with
     # at least 1 file extension
     $config->{mime_types_obj} = MIME::Types->new( only_complete => 1 );
-
-    # preload the type index hash so it's not built on the first request
-    $config->{mime_types_obj}->create_type_index;
 };
 
 # Search through all included directories for the static file
@@ -308,7 +322,7 @@ properly.
 
 If the plugin can not find the file, the request is dispatched to your
 application instead. This means you are responsible for generating a
-C<404> error if your applicaton can not process the request:
+C<404> error if your application can not process the request:
 
    # handled by static::simple, not dispatched to your application
    /images/exists.png
@@ -345,7 +359,7 @@ Logging of static files is turned off by default.
 =head1 ADVANCED CONFIGURATION
 
 Configuration is completely optional and is specified within
-C<MyApp-E<gt>config-E<gt>{static}>.  If you use any of these options,
+C<MyApp-E<gt>config-E<gt>{Plugin::Static::Simple}>.  If you use any of these options,
 this module will probably feel less "simple" to you!
 
 =head2 Enabling request logging
@@ -354,7 +368,7 @@ Since Catalyst 5.50, logging of static requests is turned off by
 default; static requests tend to clutter the log output and rarely
 reveal anything useful. However, if you want to enable logging of static
 requests, you can do so by setting
-C<MyApp-E<gt>config-E<gt>{static}-E<gt>{logging}> to 1.
+C<MyApp-E<gt>config-E<gt>{Plugin::Static::Simple}-E<gt>{logging}> to 1.
 
 =head2 Forcing directories into static mode
 
@@ -363,7 +377,7 @@ that should always be served in static mode.  Regular expressions may be
 specified using C<qr//>.
 
     MyApp->config(
-        static => {
+        'Plugin::Static::Simple' => {
             dirs => [
                 'static',
                 qr/^(images|css)/,
@@ -380,7 +394,7 @@ added to the search path when you specify an C<include_path>. You should
 use C<MyApp-E<gt>config-E<gt>{root}> to add it.
 
     MyApp->config(
-        static => {
+        'Plugin::Static::Simple' => {
             include_path => [
                 '/path/to/overlay',
                 \&incpath_generator,
@@ -424,7 +438,7 @@ If you wish to define your own extensions to ignore, use the
 C<ignore_extensions> option:
 
     MyApp->config(
-        static => {
+        'Plugin::Static::Simple' => {
             ignore_extensions => [ qw/html asp php/ ],
         },
     );
@@ -437,7 +451,7 @@ directory paths to ignore.  If using C<include_path>, the path will be
 checked against every included path.
 
     MyApp->config(
-        static => {
+        'Plugin::Static::Simple' => {
             ignore_dirs => [ qw/tmpl css/ ],
         },
     );
@@ -458,7 +472,7 @@ To override or add to the default MIME types set by the L<MIME::Types>
 module, you may enter your own extension to MIME type mapping.
 
     MyApp->config(
-        static => {
+        'Plugin::Static::Simple' => {
             mime_types => {
                 jpg => 'image/jpg',
                 png => 'image/png',
@@ -478,7 +492,7 @@ So a value of zero really means "don't cache at all", and any higher values
 will keep the file around for that long.
 
     MyApp->config(
-        static => {
+        'Plugin::Static::Simple' => {
             expires => 3600, # Caching allowed for one hour.
         },
     );
@@ -495,7 +509,7 @@ Enable additional debugging information printed in the Catalyst log.  This
 is automatically enabled when running Catalyst in -Debug mode.
 
     MyApp->config(
-        static => {
+        'Plugin::Static::Simple' => {
             debug => 1,
         },
     );
@@ -580,6 +594,18 @@ messages.
 
 C<setup> initializes all default values.
 
+=head1 DEPRECATIONS
+
+The old style of configuration using the C<'static'> config key was deprecated
+in version 0.30. A warning will be issued if this is used, and the contents of
+the config at this key will be merged with the newer C<'Plugin::Static::Simple'>
+key.
+
+Be aware that if the C<'include_path'> key under C<'static'> exists at all, it
+will be merged with any content of the same key under
+C<'Plugin::Static::Simple'>. Be careful not to set this to a non-arrayref,
+therefore.
+
 =head1 SEE ALSO
 
 L<Catalyst>, L<Catalyst::Plugin::Static>,