Catalyst-Controller-Public
view release on metacpan or search on metacpan
lib/Catalyst/Controller/Public.pm view on Meta::CPAN
package Catalyst::Controller::Public;
use Moose;
extends 'Catalyst::Controller';
our $VERSION = '0.004';
has show_debugging => (is=>'ro', required=>1, default=>sub {0});
has cache_control => (is=>'ro', isa=>'Str', predicate=>'has_cache_control');
has content_types => (is=>'ro', isa=>'ArrayRef[Str]', predicate=>'has_content_types');
has chain_base_action => (is=>'ro', isa=>'Str', predicate=>'has_chain_base_action');
has chain_pathpart => (is=>'ro', isa=>'Str', predicate=>'has_chain_pathpart');
has at => (
is=>'ro',
isa=>'Str',
required=>1,
default=>'/:namespace/:args');
after 'register_actions' => sub {
my ($self, $app) = @_;
my %base_path_attributes = $self->has_chain_base_action ?
(
Chained => [$self->chain_base_action],
PathPart => [$self->has_chain_pathpart ? $self->chain_pathpart : $self->action_namespace],
Args => []
) : (Path => [ $self->action_namespace ]);
my $action = $self->create_action(
name => 'serve_file',
code => sub { },
reverse => $self->action_namespace . '/' .'serve_file',
namespace => $self->action_namespace,
class => ref($self),
attributes => {
%base_path_attributes,
Does => ['Catalyst::ActionRole::Public'],
At => [$self->at],
ShowDebugging => [$self->show_debugging],
( $self->has_cache_control ? (CacheControl => [$self->cache_control]) : ()),
( $self->has_content_types ? (ContentTypes => $self->content_types)
: ()),
});
$app->dispatcher->register( $app, $action );
};
sub uri_args {
my $self = shift;
return $self->action_for('serve_file'), @_;
}
__PACKAGE__->meta->make_immutable;
=head1 NAME
Catalyst::Controller::Public - mount a public url to files in your Catalyst project
=head1 SYNOPSIS
package MyApp::Controller::Public;
use Moose;
extends 'Catalyst::Controller::Public';
__PACKAGE__->meta->make_immutable;
Will create an action that matches '$HOST/public/@args', for example like a URL
'localhost/public/a/b/c/d.js', that will serve file $c->{root} . '/public' . '/a/b/c/d.js'.
( run in 1.963 second using v1.01-cache-2.11-cpan-39bf76dae61 )