| POE-Component-Client-HTTPDeferred documentation | Contained in the POE-Component-Client-HTTPDeferred distribution. |
POE::Component::Client::HTTPDeferred::Deferred - Deferred class for POE::Component::Client::HTTPDeferred.
my $d = POE::Component::Client::HTTPDeferred::Deferred->new;
Create deferred object.
$d->cancel;
Cancel HTTP Request.
$d->callback($response);
An normal response callback method. This is called when http request is successful.
$d->errback($response);
An error response callback. This is called when http request is failed.
$d->addBoth($callback);
Add $callback to both callback and errback.
This is same as following:
$d->addCallbacks($callback, $callback);
$d->addCallback($callback);
Add $callback to normal callback.
$d->addCallbacks( $callback, $errback );
Add $callback to normal callback, and $errback to error callback.
$d->addErrback( $errback );
Add $errback to error callback.
Daisuke Murase <typester@cpan.org>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
| POE-Component-Client-HTTPDeferred documentation | Contained in the POE-Component-Client-HTTPDeferred distribution. |
package POE::Component::Client::HTTPDeferred::Deferred; use Any::Moose; use POE; has request => ( is => 'rw', isa => 'HTTP::Request', weak_ref => 1, required => 1, ); has client_alias => ( is => 'rw', isa => 'Str', required => 1, ); has callbacks => ( is => 'rw', isa => 'ArrayRef', lazy => 1, default => sub { [] }, ); no Any::Moose;
sub cancel { my $self = shift; $poe_kernel->post( $self->client_alias => cancel => $self->request ); $self; }
sub callback { my ($self, $res) = @_; for my $cb (@{ $self->callbacks }) { $cb->[0]->($res) if $cb->[0]; } }
sub errback { my ($self, $res) = @_; for my $cb (@{ $self->callbacks }) { $cb->[1]->($res) if $cb->[1]; } }
sub addBoth { my ($self, $cb) = @_; $self->addCallbacks($cb, $cb); }
sub addCallback { my ($self, $cb) = @_; $self->addCallbacks($cb, undef); }
sub addCallbacks { my ($self, $cb, $eb) = @_; push @{ $self->callbacks }, [ $cb, $eb ]; $self; }
sub addErrback { my ($self, $eb) = @_; $self->addCallbacks(undef, $eb); }
__PACKAGE__->meta->make_immutable;