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

NAME

CatalystX::Imports::Vars - Import application variables

BASE CLASSES

CatalystX::Imports

SYNOPSIS

  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;

DESCRIPTION

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

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

METHODS

export_into

Exports requested variables and intalls a wrapper to fill them with their respective values if needed.

export_var_into

Installs a variable into a package.

_destruct_var_name

Takes a variable name and returns it's type (scalar, array or hash) and it's symbol parts.

DIAGNOSTICS

Invalid identifier found: 'foo'

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.

Either a 1 or a hash reference expected as argument for Vars

You can import just the default variables ($self, $ctx and @args) by specifying a 1 as a parameter ...

  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.

SEE ALSO

Catalyst, CatalystX::Imports, CatalystX::Imports::Context

AUTHOR AND COPYRIGHT

Robert 'phaylon' Sedlacek <rs@474.at>

LICENSE

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