CatalystX::Imports::Vars - Import application variables
CatalystX::Imports
package MyApp::Controller::Users; use base 'Catalyst::Controller'; # use Vars => 1; for just $self, $ctx and @args use CatalystX::Imports Vars => { Stash => [qw( $user $user_rs $template )], Session => [qw( $user_id )] }; sub list: Local { $template = 'list.tt'; $user_rs = $ctx->model('User')->search; } sub view: Local { $template = 'view.tt'; $user = $ctx->model('User')->find($args[0]); } sub me: Local { $ctx->forward('view', [$user_id]); } 1;
This module allows you to bind various package vars in your controller to specific places in the framework. By default, the variables $self, $ctx and @args are exported. They have the same value as if set via
$self
$ctx
@args
my ($self, $ctx, @args) = @_;
in your action.
You can use a hash reference to specify what variables you want to bind to their respective fields in the session, flash or stash, as demonstrated in the "SYNOPSIS".
Exports requested variables and intalls a wrapper to fill them with their respective values if needed.
Installs a variable into a package.
Takes a variable name and returns it's type (scalar, array or hash) and it's symbol parts.
scalar
array
hash
You asked for the import of the var 'foo', but it is not a valid variable identifier. E.g.: '@foo', '%foo' and '$foo' are valid, but '-foo', ':foo' and 'foo' are not.
You can import just the default variables ($self, $ctx and @args) by specifying a 1 as a parameter ...
1
use CatalystX::Imports Vars => 1;
... or you can give it a hash reference and tell it what you want additionally ...
use CatalystX::Imports Vars => { Stash => [qw($foo)] };
... but you specified something else as parameter.
Catalyst, CatalystX::Imports, CatalystX::Imports::Context
Robert 'phaylon' Sedlacek <rs@474.at>
<rs@474.at>
This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.
To install CatalystX::Imports, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CatalystX::Imports
CPAN shell
perl -MCPAN -e shell install CatalystX::Imports
For more information on module installation, please visit the detailed CPAN module installation guide.