Action::Generic::Plugin::Custom - Run a custom bit of code
Create an action:
my $action = $controller->action( type => 'Custom', name => 'A Custom Action', code => sub { print "Hello world!\n" } );
.. add it to the controller ..
$controller->add_actions( $action );
And later, it gets run..
$controller->run(); # "Hello, world!\n"
The Custom action allows for running of arbitrary code. When creating the action, a code attribute must be supplied, and must be a CodeRef (in Moose terms).
Custom
code
Should you wish to pass arguments to the CODEREF, you should probably do it when creating the object. Perhaps something like:
my $foo = 'ba-nay-nay'; my $action = $controller->action( name => 'An action, with parameters', type => 'Custom', code => sub { print $foo, "\n"; } );
It's like scoping works, or something!
A CODEREF containing the code to run. In the results hashref, for this action, the return value of the coderef is captured and saved.
It is possible that the code executed could do something like die or something equally odd. I'd not suggest it.
die
This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.
Probably. Patches welcome!
Dave Houston <dhouston@cpan.org>, 2010
<dhouston@cpan.org>
To install Action::Generic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Action::Generic
CPAN shell
perl -MCPAN -e shell install Action::Generic
For more information on module installation, please visit the detailed CPAN module installation guide.