[Catalyst] Catalyst 5 preview!

Sebastian Riedel sri at oook.de
Thu Mar 31 00:47:57 CEST 2005


I previously mentioned that we are heavily working on Catalyst 5, now i 
want to give you a chance to comment on the most visible changes. (in 
case you're not on #catalyst)

With Catalyst 4 actions are defined like this:

     package MyApp::C::Foo;

     MyApp->action(

         'foo' => sub {
             my ( $self, $c ) = @_;
             $c->res->output('Hello');
         },

         '?bar' => sub {
             my ( $self, $c ) = @_;
             $c->res->output('Hello');
         },

         'lalala/foo/bar' => sub {
             my ( $self, $c ) = @_;
             $c->res->output('Hello');
         },

         '/^(\w+).html$/' => sub {
             my ( $self, $c ) = @_;
             $c->res->output('Hello');
         },

         '!end' => sub {
             my ( $self, $c ) = @_;
             $c->res->output( $c->res->output . ' Catalyst!' );
         },

     );

In Catalyst 5 it would look like this:

     package MyApp::C::Foo;

     sub foo : Global {
         my ( $self, $c ) = @_;
         $c->res->output('Hello');
     }

     sub bar : Local {
         my ( $self, $c ) = @_;
         $c->res->output('Hello');
     }

     sub lalala : Path('/lalala/foo/bar') {
         my ( $self, $c ) = @_;
         $c->res->output('Hello');
     }

     sub html : Regex('^(\w+).html$') {
         my ( $self, $c ) = @_;
         $c->res->output('Hello');
     }

     sub end : Private {
         my ( $self, $c ) = @_;
         $c->res->output( $c->res->output . ' Catalyst!' );
     }

And NO! those method names for regex and path actions are not useless, 
because now internally all actiones get a unique private address for 
forwarding, in our example:

/foo/foo
/foo/bar
/foo/lalala
/foo/html
/foo/end

And you can even inherit actions, say hello reusable components! :)

     package My::Reusable::Component;

     sub index : Local {
         my ( $self, $c ) = @_;
         $c->res->output('Hello');
     }

     package MyApp::C::Foo;

     use base 'My::Reusable::Component';

Have fun!

--
sebastian




More information about the Catalyst mailing list