NAME
Catalyst::ComponentRole::PathFrom - Derive a path using common Catalyst patterns
SYNOPSIS
package
MyApp::Model::Path;
use
Moose;
'Catalyst::Component::InstancePerContext'
;
has
ctx
=> (
is
=>
'rw'
,
weak_ref
=>1);
sub
build_per_context_instance {
my
(
$self
,
$c
) =
@_
;
$self
->ctx(
$c
);
return
$self
;
}
around
'path_from'
,
sub
{
my
(
$orig
,
$self
,
@args
) =
@_
;
return
$self
->
$orig
(
$self
->ctx,
@args
);
};
__PACKAGE__->meta->make_immutable;
package
MyApp::Controller::Example;
sub
test_a :Local {
my
(
$self
,
$c
) =
@_
;
}
sub
test_b :Local PathFrom(
'ffffff'
) {
my
(
$self
,
$c
) =
@_
;
}
sub
test_c :Local {
my
(
$self
,
$c
) =
@_
;
$c
->stash(
path_from
=>
'foo/bar'
);
}
DESCRIPTION
Common Catalyst views set a template path using a standard process, typically one based on the action or from a stash key. This component role trys to encapsulate that common pattern, with the hope that it makes it easier for people to make new Views in a consistent way. For example if you make your own custom Views this could save you some time in getting a common and expected setup.
ATTRIBUTES
This role exposes the following attributes for configuration
extension
Optional. This is a file extension added to the end of your generated file path. For example 'html', 'tt2'. You don't need to include the '.' separator.
stash_key
Has default, 'path_from'. Used to set the stash key you wish to use to programmatically set the file path pattern in your action body.
action_attribute
Has default, 'PathFrom'. Used to set the action attribute we use to get a file path pattern.
path_base
Has default "$app->config->{root}". Used to set the base path for relative paths. Usually you leave this one alone :)
METHODS
This role exposes the following public methods
path_from ( $action | $c | $c, $action | $c, $string_path )
Builds a full path to a file on the filesystem using common Catalyst conventions.
Given an $action, will return $base_path + $action->reverse + $extension OR if the $action has an attribute value for $action_attribute, return $base_path + $action_attribute + $extension.
Given $c, will do all the above (using $c->action for $action), but also check if the stash contains $stash_key and if so use that path instead.
Given $c, $action, does as above but uses the given $action instead of $c->action
Given $c, $string_path, uses $string_path instead of $action->reverse.
When using a $string_path, a $stash_key value or a value in $action_attribute you may use the following placeholders in the string (for example ':namespace/foo')
- :namespace
-
The action namespace ($action->namespace), which is typically the controller namespace
- :reverse
-
"$action->reverse" (which is basically the default
- :actionname
-
"action->name" (the subroutine method name, typically).
NOTE: if you use a $string_path, a $stash_key value or a value in $action_attribute and that value starts with '/', that is a signal you wish to use an absolute path, and we don't prepend $self->base_path. You probably won't need this...
SEE ALSO
Catalyst, Catalyst::Component, File::Spec, Moose::Role.
AUTHOR
John Napiorkowski email:jjnapiork@cpan.org
COPYRIGHT & LICENSE
Copyright 2015, 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.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 238:
Unknown directive: =over4
- Around line 240:
'=item' outside of any '=over'