Mailing List Archive

Catalyst 5 Preview, Part 3
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
Catalyst 5 Preview, Part 3 [ In reply to ]
Am 07.04.2005 um 15:20 schrieb Sebastian Riedel:

> 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! :)

Ok, after some discussions on irc it has been decided to put that
functionality in a plugin (Catalyst::Plugin::Pluggable).
So $c->forward('do_stuff') would try to forward to the do_stuff method
of the actual class.

--
sebastian
Catalyst 5 Preview, Part 3 [ In reply to ]
On Thu, 2005-04-07 at 15:20 +0200, Sebastian Riedel wrote:
> 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.

Does it just call can() on every model class, or is it doing something
fancier?

- Perrin
Catalyst 5 Preview, Part 3 [ In reply to ]
On Thu, Apr 07, 2005 at 03:20:45PM +0200, Sebastian Riedel wrote:

> 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.

How would you specify the order of the chain?

-Eugene

--
======================================================================
Eugene Eric Kim ......................... http://public.xdi.org/=eekim
Blue Oxen Associates ........................ http://www.blueoxen.org/
======================================================================
Catalyst 5 Preview, Part 3 [ In reply to ]
Am 07.04.2005 um 18:11 schrieb Eugene Eric Kim:

> On Thu, Apr 07, 2005 at 03:20:45PM +0200, Sebastian Riedel wrote:
>
>> 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.
>
> How would you specify the order of the chain?

It's now

Catalyst qw/Pluggable/;

$c->forward_all('do_stuff');

and ordered by class names.

--
sebastian
Catalyst 5 Preview, Part 3 [ In reply to ]
Am 07.04.2005 um 18:03 schrieb Perrin Harkins:

> On Thu, 2005-04-07 at 15:20 +0200, Sebastian Riedel wrote:
>> 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.
>
> Does it just call can() on every model class, or is it doing something
> fancier?

Much fancier. :)

We maintain internal structures with hashes, precompiled regexes and
Tree::Simple.
It's quite fast...i would bet much faster than Ruby-on-Rails. :)

--
sebastian