Name

SPVM::Mojo::Transaction - Transaction base class

Description

Mojo::Transaction class in SPVM is an abstract base class for transactions, like Mojo::Transaction::HTTP and Mojo::Transaction::WebSocket.

Usage

class Mojo::Transaction::MyTransaction extends Mojo::Transaction {

}

Super Class

Mojo::EventEmitter

Events

connection

Emitted when a connection has been assigned to transaction.

Examples:

$tx->on(connection => method : void ($tx : Mojo::Transaction, $connection : string) {...});

finish

Emitted when transaction is finished.

Examples:

$tx->on(finish => method : void ($tx : Mojo::Transaction) {...});

Fields

kept_alive

has kept_alive : rw byte;

Connection has been kept alive.

local_address

has local_address : rw string;

Local interface address.

local_port

has local_port : rw int;

Local interface port.

original_remote_address

has original_remote_address : rw string;

Remote interface address.

remote_address

has remote_address : virtual rw string;

Same as "original_remote_address" unless "req" has been performed via a Mojo::Message::Request#reverse_proxy. If so then the last value of X-Forwarded-For header is returned. Additionally if Mojo::Message::Request#trusted_proxies are also provided then the original address must be trusted and any X-Forwarded-For entries that are trusted are ignored, returning the last untrusted address or the first address if all are trusted.

remote_port

has remote_port : rw int;

Remote interface port.

req

has req : rw Mojo::Message::Request;

HTTP request, defaults to a Mojo::Message::Request object.

# Access request information
my $method = $tx->req->method;
my $url    = $tx->req->url->to_abs;
my $info   = $tx->req->url->to_abs->userinfo;
my $host   = $tx->req->url->to_abs->host;
my $agent  = $tx->req->headers->user_agent;
my $custom = $tx->req->headers->header("Custom-Header");
my $bytes  = $tx->req->body;
my $str    = $tx->req->text;
my $hash   = $tx->req->params->to_hash;
my $all    = $tx->req->uploads;
my $value  = $tx->req->json;

res

has res : rw Mojo::Message::Response;

HTTP response, defaults to a Mojo::Message::Response object.

# Access response information
my $code    = $tx->res->code;
my $message = $tx->res->message;
my $server  = $tx->res->headers->server;
my $custom  = $tx->res->headers->header("Custom-Header");
my $bytes   = $tx->res->body;
my $str     = $tx->res->text;
my $value   = $tx->res->json;

connection

has connection : rw string;

Connection identifier.

Class Methods

new

static method new : Mojo::Transaction ();

Create a new Mojo::Transaction object, and return it.

Instance Methods

client_read

method client_read : void ($chunk : string);

Read data client-side, used to implement user agents such as Mojo::UserAgent. Meant to be overloaded in a subclass.

client_write

method client_write : string ($server : int);

Write data client-side, used to implement user agents such as Mojo::UserAgent. Meant to be overloaded in a subclass.

completed

method completed : void ();

Low-level method to finalize transaction.

closed

method closed : void ();

Same as "completed", but also indicates that all transaction data has been sent.

is_finished

method is_finished : int ();

Check if transaction is finished.

is_websocket

method is_websocket : int ();

False, this is not a Mojo::Transaction::WebSocket object.

result

method result : Mojo::Message::Response ();

server_read

method server_read : void ($chunk : string);

Read data server-side, used to implement web servers such as Mojo::Server::Daemon. Meant to be overloaded in a subclass.

server_write

method server_write : string ($server : int);

Write data server-side, used to implement web servers such as Mojo::Server::Daemon. Meant to be overloaded in a subclass.

Well Known Child Classes

See Also

Copyright & License

Copyright (c) 2025 Yuki Kimoto

MIT License