use IO::File ();
use MIME::Types ();
use MooseX::Types::Moose qw/ArrayRef Str/;
+use Catalyst::Utils;
use namespace::autoclean;
-our $VERSION = '0.30';
+our $VERSION = '0.31';
has _static_file => ( is => 'rw' );
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;
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;
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} );
}
};
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} ];
# 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
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
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 );
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" )
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;
=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
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
specified using C<qr//>.
MyApp->config(
- static => {
+ 'Plugin::Static::Simple' => {
dirs => [
'static',
qr/^(images|css)/,
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,
C<ignore_extensions> option:
MyApp->config(
- static => {
+ 'Plugin::Static::Simple' => {
ignore_extensions => [ qw/html asp php/ ],
},
);
checked against every included path.
MyApp->config(
- static => {
+ 'Plugin::Static::Simple' => {
ignore_dirs => [ qw/tmpl css/ ],
},
);
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',
will keep the file around for that long.
MyApp->config(
- static => {
+ 'Plugin::Static::Simple' => {
expires => 3600, # Caching allowed for one hour.
},
);
is automatically enabled when running Catalyst in -Debug mode.
MyApp->config(
- static => {
+ 'Plugin::Static::Simple' => {
debug => 1,
},
);