[Catalyst] Catalyst has a Moose now :)

Sebastian Riedel sri at oook.de
Wed Apr 12 01:07:07 CEST 2006


Yes, everybody has a pony, but we have a Moose!

Today we've implemented reusable actions, but instead of plain old  
method overloading we've chosen Moose roles. ;)
And here are two simple examples:

1.
     package MyApp::Controller::Foo;
     use base 'Catalyst::Controller';
     sub bar : Global : Action('XMLRPC') {}
     1;

     package Catalyst::Action::XMLRPC;
     use Moose::Role;
     before 'execute' => sub {
         my ( $self, $controller, $c ) = @_;
         $c->xmlrpc;
     }
     1;


2.
     package MyApp::Controller::Foo;
     use base 'Catalyst::Controller';
     sub bar : Global : Action('+MyApp::Action::Test') {
         my ( $self, $c, @args ) = @_;
         $c->stash->{foo} = 23;
     }
     1;

     package MyApp::Action::Test;
     use Moose::Role;
     after 'execute' => sub {
         my ( $self, $controller, $c, @args ) = @_;
         $c->res->body( $c->stash->{foo} . join '', @args );
     }
     1;


For more informations about Moose see the following links:

     http://cpansearch.perl.org/dist/Moose/lib/Moose.pm
     http://cpansearch.perl.org/~stevan/Moose/lib/Moose/Cookbook.pod


This is a feature for *advanced* Catalyst developers, so don't be  
afraid if you don't understand it yet.


--
sebastian




More information about the Catalyst mailing list