AnyEvent recursive blocking wait with Plack
Dirk Koopman
djk at tobit.co.uk
Thu Mar 8 12:47:38 CET 2012
On 08/03/12 08:11, Marc Lehmann wrote:
> On Wed, Mar 07, 2012 at 10:14:02PM -0800, Mike Schilli<anyevent at perlmeister.com> wrote:
>> This raises an interesting question: In order to make a web application
>> truly portable between different web servers (as Plack strives to do),
>
> Yes, if Plack strives to do that, then it has to think about all of these
> things. If the lowest common denominator does not allow it, then Plack can't
> implement it.
That is *precisely* what Plack attempts to do.
>
> If not, then that's the extra value Plack delivers - somebody investing a
> lot oft ime in classifying all these servers and extracting the one common
> behaviour - much like AnyEvent.
>
Many people have spent a lot of time on Plack, probably more people and
more time than on AnyEvent. Go to any perl workshop and there will be
someone talking about some aspect or use case of Plack.
>> Say, my web app does a server-server-request. If I'm running it in
>> Plack/apache/mod_perl, I need to use synchronous methods (LWP::UserAgent
>> et al) and if I'm running in an event-based framework like
>> AnyEvent::HTTPD, I need to use event-based methods (AnyEvent::HTTP et
>> al).
>
> Well, if the Anyevent::HTTPD handler is the only one allowing that then
> you are in trouble. If it's a standard feature supported everywehre,
> then enjoy - if it's not documented well, you could always ask the Plack
> author.
>
Why not use one of the many Plack (http://plackperl.org) compatible
frameworks such as: Mojolicious (http://mojolicious.org) or Dancer
(http://perldancer.org)? Both of these frameworks (for instance) allow
web apps to query other web servers.
A mojolicious snippet to do what I think you are asking for above:
# Scrape information from remote sites
post '/title' => sub {
my $self = shift;
my $url = $self->param('url') || 'http://mojolicio.us';
$self->render_text(
$self->ua->get($url)->res->dom->html->head->title->text);
};
As far as I can tell most of the perl single threaded and some of the
multi process Plack backends use event driven IO, most of them using
Marc's stuff. Someone has solved your problem already.
Go look.
Dirk
More information about the anyevent
mailing list