NAME
AnyEvent::Mojo - Run Mojo apps using AnyEvent framework
VERSION
Version 0.1
SYNOPSIS
use strict;
use warnings;
use AnyEvent;
use AnyEvent::Mojo;
my $server = AnyEvent::Mojo->new;
$server->port(3456)->listen_queue_size(10);
$server->max_keep_alive_requests(100)->keep_alive_timeout(3);
$server->handler_cb(sub {
my ($self, $tx) = @_;
# Do whatever you want here
$you_mojo_app->handler($tx);
# Cool stats
$tx->res->headers(
'X-AnyEvent-Mojo-Request-Count' => $server->request_count
);
return $tx;
});
# Start it up and keep it running
$server->run
# integrate with other AnyEvent stuff
$server->listen
# other AnyEvent stuff here
# Run the loop
AnyEvent->condvar->recv;
# Advanced usage: use your own Connection class
$server->connection_class('MyConnectionClass');
STATUS
This is a first alpha release. The interface will change, and there is still missing funcionality, like keep alive support.
Basic HTTP/1.1 single request per connection works.
DESCRIPTION
This module allows you to integrate Mojo applications with the AnyEvent framework. For example, you can run a web interface for a long-lived AnyEvent daemon.
The AnyEvent::Mojo extends the Mojo::Server class.
To use you need to create a AnyEvent::Mojo object. You can set the port with the port()
method.
Then set the request callback with the Mojo::Server method, handler_cb()
.
This callback will be called on every request. The first parameter is the AnyEvent::Mojo server object itself, and the second parameter is a Mojo::Transaction.
The code should build the response and return.
For now, the callback is synchronous, so the response must be completed when the callback returns. Future versions will lift this restriction.
METHODS
new
The constructor. Takes no parameters, returns a server object.
host
Address where the server is listening to client requests.
port
Port where the server will listen to. Defaults to 3000.
listen_queue_size
Defines the size of the listening queue. Defaults to SOMAXCONN
.
Use
perl -MSocket -e 'print Socket::SOMAXCONN,"\n"'
to discover the default for your operating system.
max_keep_alive_requests
Number of requests that each connection will allow in keep-alive mode.
Use 0 for unlimited requests. Default is 100 requests.
keep_alive_timeout
Number of seconds (can be fractional) that the server lets open connections stay idle.
Default is 5 seconds.
request_count
Returns the number of requests the server has answered since it started.
connection_class
Sets the class name that will be used to process each connection.
Defaults to " AnyEvent::Mojo::Connection ".
listen
Starts the listening socket.
Returns nothing.
run
Starts the listening socket and kickstarts the " AnyEvent " runloop.
stop
Closes the listening socket and stops the runloop initiated by a call to run()
.
startup_banner
Called after the listening socket is started. You can override this method on your " AnyEvent::Mojo " subclasses to setup other components.
The default startup_banner
prints the URL where the server is listening to requests.
AUTHOR
Pedro Melo, <melo at cpan.org>
COPYRIGHT & LICENSE
Copyright 2008 Pedro Melo.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
3 POD Errors
The following errors were encountered while parsing the POD:
- Around line 265:
L<> starts or ends with whitespace
- Around line 277:
L<> starts or ends with whitespace
- Around line 289:
L<> starts or ends with whitespace