The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Catalyst::Controller::Public - mount a public url to files in your Catalyst project

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'.

Will also set content type, length and Last-Modified HTTP headers as needed. If the file does not exist, will not match (allowing possibly other actions to match).

You can create a URL for a static file programmtically via the following:

    sub myaction :Local {
      my ($self, $c) = @_;
      my $static_url = $c->uri_for(controller('Public')->uri_args('example.txt'));
    }

If you are using Chaining then you will probably need to specify the 'root' chain

    package MyApp::Controller::Public;

    use Moose;
    extends 'Catalyst::Controller::Public';

    __PACKAGE__->meta->make_immutable;
    __PACKAGE__->config(chain_base_action=>'/root');

DESCRIPTION

This is a simple controller that uses Catalyst::ActionRole::Public to create a single public folder for you webapplication, doing as much of the right thing as possible. Useful for starting a new project, although I imagine as time goes on you'll probably want something stronger.

This controller doesn't do anything like compile LESS to CSS, etc. If you are looking for that you might find Catalyst::Controller::SimpleCAS has more power for what you wish. This is really aimed at helping people move away from Catalyst::Plugin::Static::Simple which I really don't want to support anymore :)

METHODS

This controller defines the following methods

uri_args

Used as a helper to correctly generate a URI. For example:

    sub myaction :Local {
      my ($self, $c) = @_;
      my $static_url = $c->uri_for(controller('Public')
        ->uri_args('example.txt'));
    }

ATTRIBUTES

This controller defines the following configuration attributes. They are pretty much all just wrappers for the same configuration options for the Catalyst::ActionRole::Public

has chain_base_action => (is=>'ro', isa=>'Str', predicate=>'has_chain_base_action'); has chain_pathpart => (is=>'ro', isa=>'Str', predicate=>'has_chain_pathpart');

chain_base_action

Should be the full private path of the root chain action. This is the value you'd normally put into the subroutine attribute 'Chained'. If you are doing the normal thing this is probably called '/root'.

If you leave this undefined we assume you are not using chaining and we will create a new base path for this controller / action to match.

chain_pathpart

The value for 'PathPart' in your chaining declaration. This defaults to the namespace, which is often correct but if you are doing something fussy you might need control over it.

at

Template used to control how we build the path to find your public file. You probably want to leave this alone if you are seeking the most simple thing (which this controller is aimed at). See the documentation for 'At' over in Catalyst::ActionRole::Public if you really need to mess with this (and you might want the increased control that action role gives you anyway.

content_types

Content types that we allow to be served. By default we allow all standard types (might be more than you want, if your public directory contains things you don't want the public to see.

show_debugging

Enabled developer debugging output. Default to 0 (false, no debugging). Change to 1 if you want extended debugging info.

cache_control

Used to set the Cache-Control HTTP header (useful for caching your static assets).

Example values "public, max-age=600"

AUTHOR

John Napiorkowski email:jjnapiork@cpan.org

SEE ALSO

Catalyst, Catalyst::Controller, Plack::App::Directory, Catalyst::Controller::Assets. Catalyst::Controller::SimpleCAS

COPYRIGHT & LICENSE

Copyright 2017, John Napiorkowski email:jjnapiork@cpan.org

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.