[Catalyst] RFC: Reusable actions

Sebastian Riedel sri at oook.de
Thu Apr 6 12:27:07 CEST 2006

Now that i'm recovering from my World of Warcraft addiction i think  
it's time to move web development with Catalyst to the next level. :)

We'll start by introducing reusable actions.

The Action(class) attribute will attach before() and after() methods  
to the action sub, in a very aop-ish way.
begin and after are just placeholders, there may be more specific  
methods for param validation and the like.

Here is a first mockup to get the idea:

     package MyApp::Controller::Users;

     use base 'Catalyst::Controller';

     sub default : Private {
         my ( $self, $c ) = @_;
         $c->res->body('Welcome to the user manager!');

     sub add : Local : Action('Add') {
         my ( $self, $c ) = @_;
         $c->stash->{model} = $c->model('Users');


     package Catalyst::Action::Add;

     use base 'Catalyst::Action';

     # Unused in this example, but useful to filter request
     # data before action gets executed
     sub before {}

     sub after {
         my ( $self, $c, @args ) = @_;
         my $model = $c->stash->{model};

         # do stuff, validate args...



Multiple Acvtion() attributes for a single action are also possible.

     sub foo : Path('/bar') : Action('Bar') : Action('Baz') {}

The Catalyst::Action namespace is already taken, so we need a better  
alternative, suggestions welcome!!!


More information about the Catalyst mailing list