I'm currently writing a module to wrap a web service, done asynchronously using IO::Async. Basic summary is a bunch of methods that prepare a request, send it using Net::Async::HTTP, then yields a Future to contain the processed result once it comes back. All nicely simple stuff.
Having written a tonne of code I notice that basically none of it
depends on IO::Async at all, only the initial creation of the
Net::Async::HTTP object in the first place. The API it uses on that is
basically that it expects a single method that takes an HTTP::Request
object and returns a Future that eventually returns an HTTP::Response.
$response_future = $http->request( $request );
$response = $response_future->get;
The whole module would work easily as well given any other type of
object with this API, including anything that is actually synchronous,
such as a tiny wrapper around LWP:
package LWP::FutureReturning;
use base qw( LWP::UserAgent );
use Future;
sub request {
my $self = shift;
return Future->new->done( $self->SUPER::request( @_ ) );
}
Hey presto - have I just invented a PSGI-alike API for writing
webservices / things that use web clients, that can work synchronously,
or asynchronously using IO::Async, POE, AnyEvent, hardcoded poll(),
etc...?
I feel like I have done - or at least, I have the start of an idea that
could become it. It could do with a better name, and some more
adjustment on some concrete ideas.
Anyone any thoughts on this?
--
Paul "LeoNerd" Evans
[email protected]
ICQ# 4135350 | Registered Linux# 179460
http://www.leonerd.org.uk/
signature.asc
Description: PGP signature
