Skip to content

Commit

Permalink
slightly better method names
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 10, 2016
1 parent 7ea4766 commit ad4fecd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Channel/HTTP.pm
@@ -1,7 +1,7 @@
package Mojo::Channel::HTTP;
use Mojo::Base 'Mojo::Channel';

sub close { shift->{tx}->closed }
sub close { shift->{tx}->delivered }

sub is_server {undef}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Channel/WebSocket.pm
Expand Up @@ -3,7 +3,7 @@ use Mojo::Base 'Mojo::Channel';

use Mojo::WebSocket 'parse_frame';

sub close { shift->{tx}->closed }
sub close { shift->{tx}->delivered }

sub read {
my ($self, $chunk) = @_;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/CGI.pm
Expand Up @@ -38,7 +38,7 @@ sub run {
return undef unless $tx->is_empty || _write($res, 'get_body_chunk');

# Finish transaction
$tx->closed;
$tx->delivered;

return $res->code;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -107,7 +107,7 @@ sub _close {
my ($self, $id) = @_;

# Finish gracefully
if (my $tx = $self->{connections}{$id}{tx}) { $tx->closed }
if (my $tx = $self->{connections}{$id}{tx}) { $tx->delivered }

delete $self->{connections}{$id};
}
Expand All @@ -121,7 +121,7 @@ sub _finish {
return $self->_remove($id) if $tx->is_websocket;

# Finish transaction
delete($c->{tx})->closed;
delete($c->{tx})->delivered;

# Upgrade connection to WebSocket
if (my $ws = $tx->next) {
Expand All @@ -132,11 +132,11 @@ sub _finish {
= Mojo::Channel::WebSocket->new(tls => $c->{tls}, tx => $ws);
weaken $self;
$ws->on(resume => sub { $self->_write($id) });
$ws->opened;
$ws->established;
}

# Failed upgrade
else { $ws->closed }
else { $ws->delivered }
}

# Close connection if necessary
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/PSGI.pm
Expand Up @@ -44,7 +44,7 @@ package Mojo::Server::PSGI::_IO;
use Mojo::Base -base;

# Finish transaction
sub close { shift->{tx}->closed }
sub close { shift->{tx}->delivered }

sub getline {
my $self = shift;
Expand Down
18 changes: 9 additions & 9 deletions lib/Mojo/Transaction.pm
Expand Up @@ -10,14 +10,14 @@ has [
has req => sub { Mojo::Message::Request->new };
has res => sub { Mojo::Message::Response->new };

sub closed { shift->_state(qw(finished finish)) }

sub connection {
my $self = shift;
return $self->emit(connection => $self->{connection} = shift) if @_;
return $self->{connection};
}

sub delivered { shift->_state(qw(finished finish)) }

sub error { $_[0]->req->error || $_[0]->res->error }

sub is_finished { (shift->{state} // '') eq 'finished' }
Expand Down Expand Up @@ -156,20 +156,20 @@ HTTP response, defaults to a L<Mojo::Message::Response> object.
L<Mojo::Transaction> inherits all methods from L<Mojo::EventEmitter> and
implements the following new ones.
=head2 closed
$tx->closed;
Low-level signal that the underlying connection is finished with this
transaction.
=head2 connection
my $id = $tx->connection;
$tx = $tx->connection($id);
Connection identifier.
=head2 delivered
$tx->delivered;
Low-level signal that the underlying connection is finished with this
transaction.
=head2 error
my $err = $tx->error;
Expand Down
30 changes: 15 additions & 15 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -48,13 +48,15 @@ sub build_message {
return build_frame $self->masked, @$frame;
}

sub closed {
sub connection { shift->handshake->connection }

sub delivered {
my $self = shift;
$self->{state} = 'finished';
return $self->emit(finish => $self->{close} ? (@{$self->{close}}) : 1006);
}

sub connection { shift->handshake->connection }
sub established { shift->{open}++ }

sub finish {
my $self = shift;
Expand Down Expand Up @@ -86,8 +88,6 @@ sub new {
return $self;
}

sub opened { shift->{open}++ }

sub protocol { shift->res->headers->sec_websocket_protocol }

sub remote_address { shift->handshake->remote_address }
Expand Down Expand Up @@ -363,18 +363,24 @@ and implements the following new ones.
Build WebSocket message.
=head2 closed
=head2 connection
my $id = $ws->connection;
Connection identifier.
=head2 delivered
$ws->closed;
$ws->delivered;
Low-level signal that the underlying connection is finished with this
transaction.
=head2 connection
=head2 established
my $id = $ws->connection;
$ws->established;
Connection identifier.
Low-level signal that the underlying connection has been established.
=head2 finish
Expand Down Expand Up @@ -436,12 +442,6 @@ Construct a new L<Mojo::Transaction::WebSocket> object and subscribe to
L</"frame"> event with default message parser, which also handles C<PING> and
C<CLOSE> frames automatically.
=head2 opened
$ws->opened;
Low-level signal that the underlying connection has been established.
=head2 protocol
my $proto = $ws->protocol;
Expand Down

0 comments on commit ad4fecd

Please sign in to comment.