[Catalyst] Catalyst 5 preview!
Alan Humphrey
alan.humphrey at comcast.net
Thu Mar 31 18:24:48 CEST 2005
Looks good to me. I like how it makes things clearer.
Two questions:
1) what is the difference between Global and Local? When would I use
one vs. the other vs. Path?
2) will argument passing via the URL still be accomplished only via
regex?
- Alan
-----Original Message-----
From: catalyst-bounces at lists.rawmode.org
[mailto:catalyst-bounces at lists.rawmode.org] On Behalf Of Sebastian
Riedel
Sent: Wednesday, March 30, 2005 2:48 PM
To: catalyst at lists.rawmode.org
Subject: [Catalyst] Catalyst 5 preview!
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
_______________________________________________
Catalyst mailing list
Catalyst at lists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst
More information about the Catalyst
mailing list