1Mojo::Transaction(3)  User Contributed Perl Documentation Mojo::Transaction(3)
2
3
4

NAME

6       Mojo::Transaction - Transaction Base Class
7

SYNOPSIS

9           use base 'Mojo::Transaction';
10

DESCRIPTION

12       Mojo::Transaction is an abstract base class for transactions.
13

ATTRIBUTES

15       Mojo::Transaction implements the following attributes.
16
17   "connection"
18           my $connection = $tx->connection;
19           $tx            = $tx->connection($connection);
20
21       Connection identifier or socket.
22
23   "finished"
24           my $cb = $tx->finished;
25           $tx    = $tx->finished(sub {...});
26
27       Callback signaling that the transaction has been finished.
28
29           $tx->finsihed(sub {
30               my $self = shift;
31           });
32
33   "keep_alive"
34           my $keep_alive = $tx->keep_alive;
35           $tx            = $tx->keep_alive(1);
36
37       Connection can be kept alive.
38
39   "kept_alive"
40           my $kept_alive = $tx->kept_alive;
41           $tx            = $tx->kept_alive(1);
42
43       Connection has been kept alive.
44
45   "local_address"
46           my $local_address = $tx->local_address;
47           $tx               = $tx->local_address($address);
48
49       Local interface address.
50
51   "local_port"
52           my $local_port = $tx->local_port;
53           $tx            = $tx->local_port($port);
54
55       Local interface port.
56
57   "previous"
58           my $previous = $tx->previous;
59           $tx          = $tx->previous(Mojo::Transaction->new);
60
61       Previous transaction that triggered this followup transaction.
62
63   "remote_address"
64           my $remote_address = $tx->remote_address;
65           $tx                = $tx->remote_address($address);
66
67       Remote interface address.
68
69   "remote_port"
70           my $remote_port = $tx->remote_port;
71           $tx             = $tx->remote_port($port);
72
73       Remote interface port.
74
75   "resume_cb"
76           my $cb = $tx->resume_cb;
77           $tx    = $tx->resume_cb(sub {...});
78
79       Callback to be invoked whenever the transaction is resumed.
80

METHODS

82       Mojo::Transaction inherits all methods from Mojo::Base and implements
83       the following new ones.
84
85   "client_read"
86           $tx = $tx->client_read($chunk);
87
88       Read and process client data.
89
90   "client_write"
91           my $chunk = $tx->client_write;
92
93       Write client data.
94
95   "error"
96           my $message          = $message->error;
97           my ($message, $code) = $message->error;
98
99       Parser errors and codes.
100
101   "is_done"
102           my $done = $tx->is_done;
103
104       Check if transaction is done.
105
106   "is_paused"
107           my $paused = $tx->is_paused;
108
109       Check if transaction is paused.
110
111   "is_websocket"
112           my $is_websocket = $tx->is_websocket;
113
114       Check if transaction is a WebSocket.
115
116   "is_writing"
117           my $writing = $tx->is_writing;
118
119       Check if transaction is writing.
120
121   "pause"
122           $tx = $tx->pause;
123
124       Pause transaction, it can still read but writing is disabled while
125       paused.
126
127   "req"
128           my $req = $tx->req;
129
130       Transaction request.
131
132   "res"
133           my $res = $tx->res;
134
135       Transaction response.
136
137   "resume"
138           $tx = $tx->resume;
139
140       Resume transaction.
141
142   "server_close"
143           $tx = $tx->server_close;
144
145       Transaction closed.
146
147   "server_read"
148           $tx = $tx->server_read($chunk);
149
150       Read and process server data.
151
152   "server_write"
153           my $chunk = $tx->server_write;
154
155       Write server data.
156
157   "success"
158           my $res = $tx->success;
159
160       Returns the Mojo::Message::Response object ("res") if transaction was
161       successful or "undef" otherwise.  Connection and parser errors have
162       only a message in "error", 400 and 500 responses also a code.  Note
163       that this method is EXPERIMENTAL and might change without warning!
164
165           if (my $res = $tx->success) {
166               print $res->body;
167           }
168           else {
169               my ($message, $code) = $tx->error;
170               if ($code) {
171                   print "$code $message response.\n";
172               }
173               else {
174                   print "Connection error: $message\n";
175               }
176           }
177
178       Error messages can be accessed with the "error" method of the
179       transaction object.
180

SEE ALSO

182       Mojolicious, Mojolicious::Guides, <http://mojolicious.org>.
183
184
185
186perl v5.12.3                      2010-08-17              Mojo::Transaction(3)
Impressum