AnyEvent-HTTPD-ExtDirect
view release on metacpan or search on metacpan
lib/AnyEvent/HTTPD/ExtDirect.pm view on Meta::CPAN
### PUBLIC INSTANCE METHOD ###
#
# Run the server
#
sub run {
my ($self) = @_;
my $config = $self->config;
$self->set_callbacks(
api_path => $config->api_path,
router_path => $config->router_path,
poll_path => $config->poll_path,
);
$self->SUPER::run();
}
### PUBLIC INSTANCE METHOD ###
#
lib/AnyEvent/HTTPD/ExtDirect.pm view on Meta::CPAN
'Content-Length' => $content_length,
},
$http_body,
]);
$self->stop_request;
}
### PUBLIC INSTANCE METHOD ###
#
# Register the callbacks for Ext.Direct handlers.
# This effectively "primes" the server but does not make it
# enter a blocking wait.
#
sub set_callbacks {
my ($self, %arg) = @_;
my $config = $self->config;
my $api_path = $arg{api_path} || $config->api_path;
my $router_path = $arg{router_path} || $config->router_path;
my $poll_path = $arg{poll_path} || $config->poll_path;
$self->reg_cb(
$api_path => $self->can('handle_api'),
lib/AnyEvent/HTTPD/ExtDirect.pod view on Meta::CPAN
=head2 Non-blocking server
AnyEvent::HTTPD::ExtDirect can be used not only as a standalone event
based application server, but also as an embedded Ext.Direct engine
in a larger event based application. This is important and is worth
repeating: the non-blocking server approach will only work if your
application is event based, adhering to L<AnyEvent> conventions!
To use AnyEvent::HTTPD::ExtDirect as a non-blocking server, create
an instance of it, prime it by calling L</set_callbacks>, and
save a reference to it:
my $httpd = AnyEvent::HTTPD::ExtDirect->new( config => $config );
$httpd->set_callbacks( ... );
Saving a reference to the server instance is important; if you don't
save it, the server instance will be destroyed soon after creation,
and you will spend a lot of time trying to figure out why it does
not accept requests. So, this will B<not> work as expected:
AnyEvent::HTTPD::ExtDirect->new( ... )->set_callbacks( ... );
Same goes for other AnyEvent(ish) things you may want to create in
your application, including file handle read, timed callbacks, etc.
=head1 CAVEATS
The considerations below are specific to AnyEvent::HTTPD::ExtDirect:
=head2 Host names vs IP addresses
L<AnyEvent::HTTPD> constructor does not perform host name lookup
and will break if you pass in a host name string instead of IP
address. The only exception is C<localhost> that will be substituted
lib/AnyEvent/HTTPD/ExtDirect.pod view on Meta::CPAN
L<RPC::ExtDirect::EventProvider> when instantiating EventProvider
objects in AnyEvent::HTTPD::ExtDirect environment.
=item other
Any other parameter will be passed on to the underlying
L<AnyEvent::HTTPD> constructor.
=back
=item C<set_callbacks>
Instance method. Registers Ext.Direct handlers for API generator,
Router, and Event Provider with the AnyEvent::HTTPD transport
mechanism, effectively "priming" the server instance without
entering a blocking wait. Accepts named arguments in a hash.
This method will be called internally by L</run> so you do not
need to call it explicitly unless you want to use a non-blocking
server option. See L</"Non-blocking server"> section above.
lib/AnyEvent/HTTPD/ExtDirect.pod view on Meta::CPAN
=item C<poll_path>
URI on which the Event Provider should listen to Ext.Direct event
polling requests. Defaults to server Config option of the same
name; this parameter mainly exists for testing overrides.
=back
=item C<run>
Instance method. Sets the Ext.Direct callbacks with default Config
URIs (see L</set_callbacks>), and enters a blocking wait by
calling underlying AnyEvent::HTTPD's C<run> method.
This method does not accept arguments, and never returns.
=back
=head1 ACCESSOR METHODS
For AnyEvent::HTTPD::ExtDirect, the following
L<accessor methods|RPC::ExtDirect::Config/"ACCESSOR METHODS"> are
t/lib/RPC/ExtDirect/Test/Util/AnyEvent.pm view on Meta::CPAN
debug_serialize => 1,
%$config,
);
my $server = AnyEvent::HTTPD::ExtDirect->new(
host => $host,
port => $port,
config => $cfg_obj,
);
$server->set_callbacks(
api_path => $cfg_obj->api_path,
router_path => $cfg_obj->router_path,
poll_path => $cfg_obj->poll_path,
);
my $req_str = $req->as_string("\r\n");
my $actual_host = $server->host;
my $actual_port = $server->port;
( run in 0.564 second using v1.01-cache-2.11-cpan-d6f9594c0a5 )