Dancer::Plugin::Async - Dancer plugin to write async request handlers with Twiggy
version 0.1
This plugin helps you to write async web applications (or partly async web apps) using Twiggy and Dancer. It provides the async keyword and a default Application that you can use with Plack.
async
In your lib/myapp.pm:
use Dancer::Plugin::Async; use AnyEvent; # Async request handler, responds when the timer triggers async 'get' => '/timer' => sub { my $respond = respond; my $t; $t = AnyEvent->timer(after => 1, cb => sub { $respond->([ 200, [], [ 'foo!' ]]); }); }; # Normal Dancer route handler, blocking get '/blocking' => sub { redirect '/timer'; };
In your bin/app.pl:
use Dancer; use Dancer::Plugin::Async; use Twiggy; use AnyEvent; use myapp; use EV; my $server = Twiggy::Server->new( host => '0.0.0.0', port => 3000, ); $server->register_service(Dancer::Plugin::Async::app()); EV::loop
In the callbacks (for example of the timer in the SYNOPSIS), you cannot use many of the normal Dancer keywords such as template, redirect, etc. This is due to Dancer accessing Dancer::SharedData, which is not available later on. If anyone has a good idea on how to solve this problem, suggestions/patches are very welcome.
SYNOPSIS
Michael Stapelberg, <michael at stapelberg.de>
<michael at stapelberg.de>
Please report any bugs or feature requests to bug-dancer-plugin-async at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Plugin-Async. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-dancer-plugin-async at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Dancer::Plugin::Async
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Plugin-Async
Copyright 2010 Michael Stapelberg.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Dancer::Plugin::Async, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::Async
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::Async
For more information on module installation, please visit the detailed CPAN module installation guide.