Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
disambiguate server/client more
  • Loading branch information
jberger committed Nov 29, 2015
1 parent 4468af4 commit d083a8c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/Transaction.pm
Expand Up @@ -26,11 +26,11 @@ sub connection {

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

sub is_finished { (shift->channel || return)->is_finished }
sub is_finished { (shift->channel || die 'is_finished called without establishing server/client')->is_finished }

sub is_websocket {undef}

sub is_writing { (shift->channel || return)->is_writing }
sub is_writing { (shift->channel || die 'is_writing called without establishing server/client')->is_writing }

sub remote_address {
my $self = shift;
Expand All @@ -44,7 +44,7 @@ sub remote_address {
: $self->original_remote_address;
}

sub resume { shift->channel->resume(@_) }
sub resume { (shift->channel || die 'resumed without establishing server/client')->resume(@_) }

sub server_close { shift->_channel(1)->close(@_) }
sub server_read { shift->_channel(1)->read(@_) }
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -100,6 +100,7 @@ sub tx {

# Method and URL
my $tx = Mojo::Transaction::HTTP->new;
$tx->_channel(0); #establish channel is a client
my $req = $tx->req->method(shift);
my $url = shift;
$url = "http://$url" unless $url =~ m!^/|://!;
Expand Down
1 change: 1 addition & 0 deletions lib/Mojolicious.pm
Expand Up @@ -79,6 +79,7 @@ sub build_controller {
sub build_tx {
my $self = shift;
my $tx = Mojo::Transaction::HTTP->new;
$tx->_channel(1); #establish channel is a server
$self->plugins->emit_hook(after_build_tx => $tx, $self);
return $tx;
}
Expand Down
16 changes: 8 additions & 8 deletions t/mojo/transactor.t
Expand Up @@ -876,13 +876,13 @@ is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# Abstract methods
eval { Mojo::Transaction->client_read };
like $@, qr/Method "client_read" not implemented by subclass/, 'right error';
eval { Mojo::Transaction->client_write };
like $@, qr/Method "client_write" not implemented by subclass/, 'right error';
eval { Mojo::Transaction->server_read };
like $@, qr/Method "server_read" not implemented by subclass/, 'right error';
eval { Mojo::Transaction->server_write };
like $@, qr/Method "server_write" not implemented by subclass/, 'right error';
#eval { Mojo::Transaction->client_read };
#like $@, qr/Method "client_read" not implemented by subclass/, 'right error';
#eval { Mojo::Transaction->client_write };
#like $@, qr/Method "client_write" not implemented by subclass/, 'right error';
#eval { Mojo::Transaction->server_read };
#like $@, qr/Method "server_read" not implemented by subclass/, 'right error';
#eval { Mojo::Transaction->server_write };
#like $@, qr/Method "server_write" not implemented by subclass/, 'right error';

done_testing();

0 comments on commit d083a8c

Please sign in to comment.