
CatalystX::Imports::Context::Default - Default Context Library


package MyApp::Controller::Foo;
use base 'Catalyst::Controller';
use CatalystX::Imports Context => ':all';
sub foo: Local {
stash( rs => model('Foo')->find(param('foo')) );
}
1;

This package represents the default library of Context exports.
There are some tags you can use to import groups of functions:
:allImports all registered exports in their real names. Aliases will not be included in the export. You still have to specify them explicitly.
:introAll exports in the "INTROSPECTION EXPORTS" section.
:mvcThe "model", "view" and "controller" exports.
:reqExports all functions in the "REQUEST EXPORTS" section.
:paramContains the "has_param" and "param" exports.
:logEverything defined in the "LOGGING AND DEBUGGING EXPORTS" section.
:debugThe "debug" and "log_debug" exports.
For more information on the import syntax, please consult CatalystX::Imports::Context.

The action function is a shortcut to lookup action(chain) objects. When called without arguments:
my $current_action_object = action;
it will return the current action as stored in $c->action. You can also specify the action of which you'd like to have the object. It accepts simple action names (not starting with a slash) to return an action relative to the current controller:
my $action = action('list');
But it also allows you to pass an absolute action path:
my $action = action('/foo/bar/edit');
These three functions are shortcuts to the corresponding method on the context object. Therefore, the expression
my $person = model('DBIC::Person')->find(23);
will usually do the same as
my $person = $c->model('DBIC::Person')->find(23);
Note, however, that these three exports are aware of the component_prefix configuration setting.
See also "$c->uri_for" in Catalyst. Here is an example in combination with "action":
my $edit_uri = uri_for(action('edit'), 23);
See also "$c->path_to" in Catalyst. This utility function builds a path by your specification, starting at the application root:
my $pdf_dir = path_to(qw( root data pdfs ));

See "$c->stash" in Catalyst, for which this function is a shortcut:
stash(rs => $result_set); # stores the key 'rs' in the stash
...
my $rs = stash->{rs}; # retrieves it again
Returns the last called action's passed arguments.
Returns the current Catalyst::Request object. You can also import its alias req.
if (request->method eq 'POST') {
...
}
Returns the current Catalyst::Response object. You can also import its alias res.
response->status(404);
response->body('I misplaced that resource.');
Returns the current requests captures.
Boolean test if a query parameter was submitted with the request.
sub search: Local {
if (has_param('q')) {
my $q = param('q');
stash( result => model('Foo')->search({ bar => $q }) );
}
}
The same as a call to the param method on the current Catalyst::Request object.

This function allows you to nest debugging code directly in your actions and only execute it when debugging is turned on.
debug { # runs only in debug mode
my $foo = 'something';
my @bar = (1 .. 10_000);
warn "Doing $foo on $_" for @bar;
log_debug('Done.');
};
Outputs content to the logging channel, but only if the application is in debug mode.
These functions log to the info, warn and error channels.

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

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

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