[Catalyst] Catalyst 5 Preview, Part 3
Sebastian Riedel
sri at oook.de
Thu Apr 7 15:20:45 CEST 2005
You may know the common problem of pluggable applications.
For example MojoMojo uses multiple chained formatters to render
different types of input (pod, textile, wikiwords...), just put a new
formatter module in the right directory and it will become part of the
chain...
Thanks to Module::Pluggable thats not really a big problem, but now in
Cat5 it's even more simple! :)
package MyApp::C::Page;
sub show : Local {
my ( $self, $c, $id ) = @_;
$c->stash->{content} =
MyApp::M::CDBI::Page->retrieve($id)->content;
$c->forward('render_content');
}
package MyApp::C::Formatter::Pod;
sub render_content : Private {
my ( $self, $c ) = @_;
# do stuff with $c->stash->{content};
return 1;
}
package MyApp::C::Formatter::Textile;
sub render_content : Private {
my ( $self, $c ) = @_;
# do stuff with $c->stash->{content};
return 1;
}
package MyApp::C::Formatter::Wikiwords;
sub render_content : Private {
my ( $self, $c ) = @_;
# do stuff with $c->stash->{content};
return 1;
}
Now if someone requests http://localhost:3000/page/show/1 it would
thanks to the relative forward "$c->forward('render_content')", call
all private "render_content" actions in the whole application.
Those actions are called in a chain, just like auto actions, so you can
break the chain simply by returning 0.
This makes pluggable applications absolute trivial! ;)
--
sebastian
More information about the Catalyst
mailing list