The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Dancer::Plugin::Async - Dancer plugin to write async request handlers with Twiggy

VERSION

version 0.1

DESCRIPTION

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.

SYNOPSIS

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

PROBLEMS

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.

AUTHOR

Michael Stapelberg, <michael at stapelberg.de>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Dancer::Plugin::Async

You can also look for information at:

LICENSE AND COPYRIGHT

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.