Author image Αριστοτέλης Παγκαλτζής

NAME

Catalyst::Plugin::Digress - A cleaner, simpler, action-only $c->forward

SYNOPSIS

 $c->forward( 'some/other/action' );
 $c->forward( 'action_in_same_controller' );
 $c->forward( $self->action_for( 'action_in_same_controller' ) );
 
 my %form = $c->forward( 'validate_params', {
   name  => { required => },
   email => { type => 'Str' },
 } );

 $c->digress( $c->view ); # FAIL: cannot digress to components

DESCRIPTION

This plugin gives you the useful part of the Catalyst forward method without the weirdness (or the madness).

METHODS

digress

This is akin to forward, with the following differences:

  • It does not catch exceptions (the most important benefit).

  • It passes parameters like in a normal Perl method call.

  • It does not mess with $c->request->arguments.

  • It preserves list vs scalar context for the call.

  • It does not walk the Perl call stack every time (or ever, even once) to figure out what its own name was (or for any other purpose).

  • It cannot forward to components, only actions (because don’t ask how forwarding to components works).

In other words, is almost identical to a straight method call:

 package MyApp::Controller::Some;
 sub other_action : Private { ... }

 package MyApp::Controller::Root;
 sub index : Path {
   my ( $c, @some_args ) = ( shift, @_ );
   # ...
   my @some_return = $c->digress( '/some/other_action', @any_old_args );
   # this is nearly identical to the following line:
   my @some_return = $c->controller( 'Some' )->other_action( $c, @any_old_args );
   # ...
 }

Except, of course, that it takes an action path instead of a plain method name, and it maintains the Catalyst action stack for you just like forward would, which keeps various Catalyst mechanisms working, such as calling forward and friends from other_action with a local action name.

AUTHOR

Aristotle Pagaltzis <pagaltzis@gmx.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by Aristotle Pagaltzis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.