Pascal Gaudette > MojoX-UserAgent > MojoX::UserAgent::Transaction

Download:
MojoX-UserAgent-0.21.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

MojoX::UserAgent::Transaction - Basic building block of MojoX::UserAgent, encapsulates a single HTTP exchange.

SYNOPSIS ^

    my $tx = MojoX::UserAgent::Transaction->new(
        {   url     => 'http://www.some.host.com/bla/',
            method  => 'POST',
            ua      => $ua,
            id      => '123456',
            headers => {
                'Expect'       => '100-continue',
                'Content-Type' => 'text/plain'
            },
            body     => 'Hello!',
            callback => sub {
                my ($ua, $tx) = @_;
                ok(!$tx->has_error, 'Completed');
                is($tx->id, '123456', 'Request ID');
                is($tx->res->code, 200, 'Status 200');
            }
        }
    };

    $ua->spool($tx);

DESCRIPTION ^

A subclass of Mojo::Transaction::Single, this class simply adds the few extra elements that are needed by MojoX::UserAgent.

ATTRIBUTES ^

This class inherits all the attributes of Mojo::Transaction::Single, and adds the following.

done_cb

The subroutine that will be called once the transaction is completed. When invoked, this sub is passed two arguments: the UserAgent object that performed the transaction and the transaction itself.

hops

The number of hops (ie redirects) that this transaction has gone through.

id

An optional transaction identifier. Not used internally by the class, but preserved across redirects and accessible to the callback.

original_req

If the transaction is redirected, this holds the original request object.

ua

A pointer back to the MojoX::UserAgent to which this transaction was spooled.

METHODS ^

MojoX::UserAgent::Transaction inherits all methods from Mojo::Transaction::Single and implements the following new ones.

new

Constructor that accepts a reference to a hash of named arguments. This hash must contain the following key/value pairs:

It may also contain any/all of the following:

client_connect

Called when the transaction is about to be sent out, this method is used to add the User-Agent and request cookies to the outgoing request.

syntax highlighting: