[Catalyst] Continuations anyone? :)
Sebastian Riedel
sri at oook.de
Fri Apr 21 13:07:34 CEST 2006
Yea, maybe i've been playing too much with Seaside,
but here is an example for a (fake) continuation plugin. =)
Since Perl5 doesn't support real continuations we can just serialize
the action object,
but thats enough to have a lot of fun.
Usage is surprisingly similar to Seaside as you can see in this small
example.
package MyApp::Controller::Counter;
use base 'Catalyst::Controller';
sub counter : Global : MyAction('Counter') {
my ( $self, $c ) = @_;
my $up = $c->continue('up');
my $down = $c->continue('down');
my $counter = $c->action->{counter} || 0;
$c->res->body(<<"EOF");
Counter: $counter<br/>
<a href="$up">++</a>
<a href="$down">--</a>
EOF
}
package MyApp::Action::Counter;
use Moose::Role;
sub up { shift->{counter}++ }
sub down { shift->{counter}-- }
The action sub "counter" connects everything.
After the first request you get two links to click ++ and --,
both will have urls like http://localhost:3000/?
_k=d327fe00b450b69e241a2740431090c9.
They are callbacks to the methods "up" and "down" in the action class.
(the action sub "counter" will get executed again after the callback
finished)
The plugin is already written but requires the moose branch of Catalyst
and a patched Catalyst::Action, so it would be quite useless to
release it yet.
If you want to test it anyhow just tell me in #catalyst. ;)
Disclaimer: This is all just a fun experiment, continuations may look
cool
(because they require a whole different thinking than traditional web
development),
but they also get unmaintainable very fast and require a lot more
resources.
--
sebastian
More information about the Catalyst
mailing list