Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved transaction descriptions and added a few examples
  • Loading branch information
kraih committed Nov 5, 2011
1 parent c936461 commit c44f161
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 58 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.25 2011-11-06 00:00:00
- Improved documentation.

2.24 2011-11-05 00:00:00
- Added EXPERIMENTAL canonicalize method to Mojo::URL.
- Improved documentation.
Expand Down
46 changes: 22 additions & 24 deletions lib/Mojo/Transaction.pm
Expand Up @@ -2,12 +2,15 @@ package Mojo::Transaction;
use Mojo::Base 'Mojo::EventEmitter';

use Carp 'croak';
use Mojo::Message::Request;
use Mojo::Message::Response;

has [qw/connection kept_alive local_address local_port previous remote_port/];
has req => sub { Mojo::Message::Request->new };
has res => sub { Mojo::Message::Response->new };

# "Please don't eat me! I have a wife and kids. Eat them!"
sub client_close { shift->server_close(@_) }

sub client_read { croak 'Method "client_read" not implemented by subclass' }
sub client_write { croak 'Method "client_write" not implemented by subclass' }

Expand Down Expand Up @@ -73,23 +76,14 @@ sub remote_address {
return $self->{remote_address};
}

sub req { croak 'Method "req" not implemented by subclass' }
sub res { croak 'Method "res" not implemented by subclass' }

sub resume {
my $self = shift;
if (($self->{state} || '') eq 'paused') { $self->{state} = 'write_body' }
elsif (!$self->is_writing) { $self->{state} = 'write' }
$self->emit('resume');
return $self;
}

sub server_close {
my $self = shift;
$self->emit('finish');
return $self;
return $self->emit('resume');
}

sub server_close { shift->emit('finish') }
sub server_read { croak 'Method "server_read" not implemented by subclass' }
sub server_write { croak 'Method "server_write" not implemented by subclass' }

Expand Down Expand Up @@ -173,6 +167,8 @@ Local interface port.
Previous transaction that triggered this followup transaction.
say $tx->previous->req->url->path;
=head2 C<remote_address>
my $remote_address = $tx->remote_address;
Expand All @@ -187,6 +183,20 @@ Remote interface address.
Remote interface port.
=head2 C<req>
my $req = $tx->req;
$tx = $tx->req(Mojo::Message::Request->new);
HTTP 1.1 request, defaults to a L<Mojo::Message::Request> object.
=head2 C<res>
my $res = $tx->res;
$tx = $tx->res(Mojo::Message::Response->new);
HTTP 1.1 response, defaults to a L<Mojo::Message::Response> object.
=head1 METHODS
L<Mojo::Transaction> inherits all methods from L<Mojo::EventEmitter> and
Expand Down Expand Up @@ -235,18 +245,6 @@ False.
Check if transaction is writing.
=head2 C<req>
my $req = $tx->req;
Transaction request, usually a L<Mojo::Message::Request> object.
=head2 C<res>
my $res = $tx->res;
Transaction response, usually a L<Mojo::Message::Response> object.
=head2 C<resume>
$tx = $tx->resume;
Expand Down
22 changes: 1 addition & 21 deletions lib/Mojo/Transaction/HTTP.pm
@@ -1,13 +1,8 @@
package Mojo::Transaction::HTTP;
use Mojo::Base 'Mojo::Transaction';

use Mojo::Message::Request;
use Mojo::Message::Response;
use Mojo::Transaction::WebSocket;

has req => sub { Mojo::Message::Request->new };
has res => sub { Mojo::Message::Response->new };

# "What's a wedding? Webster's dictionary describes it as the act of
# removing weeds from one's garden."
sub client_read {
Expand Down Expand Up @@ -356,22 +351,7 @@ requests.
=head1 ATTRIBUTES
L<Mojo::Transaction::HTTP> inherits all attributes from L<Mojo::Transaction>
and implements the following new ones.
=head2 C<req>
my $req = $tx->req;
$tx = $tx->req(Mojo::Message::Request->new);
HTTP 1.1 request, defaults to a L<Mojo::Message::Request> object.
=head2 C<res>
my $res = $tx->res;
$tx = $tx->res(Mojo::Message::Response->new);
HTTP 1.1 response, defaults to a L<Mojo::Message::Response> object.
L<Mojo::Transaction::HTTP> inherits all attributes from L<Mojo::Transaction>.
=head1 METHODS
Expand Down
28 changes: 16 additions & 12 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -293,9 +293,7 @@ sub server_read {
}

# Resume
$self->emit('resume');

return $self;
return $self->emit('resume');
}

sub server_write {
Expand Down Expand Up @@ -450,7 +448,7 @@ Raw WebSocket data to write.
my $connection = $ws->connection;
The connection this websocket is using.
Alias for C<$ws-E<gt>handshake-E<gt>connection>.
=head2 C<finish>
Expand All @@ -468,13 +466,13 @@ True.
my $local_address = $ws->local_address;
The local address of this WebSocket.
Alias for C<$ws-E<gt>handshake-E<gt>local_address>.
=head2 C<local_port>
my $local_port = $ws->local_port;
The local port of this WebSocket.
Alias for C<$ws-E<gt>handshake-E<gt>local_port>.
=head2 C<parse_frame>
Expand All @@ -486,31 +484,37 @@ Parse WebSocket frame.
my $remote_address = $ws->remote_address;
The remote address of this WebSocket.
Alias for C<$ws-E<gt>handshake-E<gt>remote_address>.
=head2 C<remote_port>
my $remote_port = $ws->remote_port;
The remote port of this WebSocket.
Alias for C<$ws-E<gt>handshake-E<gt>remote_port>.
=head2 C<req>
my $req = $ws->req;
The original handshake request.
Alias for C<$ws-E<gt>handshake-E<gt>req>.
Usually refers to a L<Mojo::Message::Request> object.
$ws->req->headers->header('X-Bender' => 'Bite my shiny metal ass!');
=head2 C<res>
my $req = $ws->res;
my $res = $ws->res;
Alias for C<$ws-E<gt>handshake-E<gt>res>.
Usually refers to a L<Mojo::Message::Response> object.
The original handshake response.
$ws->res->headers->header('X-Bender' => 'Bite my shiny metal ass!');
=head2 C<resume>
$ws = $ws->resume;
Resume transaction.
Alias for C<$ws-E<gt>handshake-E<gt>resume>.
=head2 C<send_frame>
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -35,7 +35,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.24';
our $VERSION = '2.25';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down

0 comments on commit c44f161

Please sign in to comment.