Skip to content

Commit

Permalink
fixed small inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 5, 2012
1 parent 11f089d commit 149210c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
13 changes: 7 additions & 6 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -33,7 +33,8 @@ has transactor => sub { Mojo::UserAgent::Transactor->new };
for my $name (qw/DELETE GET HEAD OPTIONS PATCH POST PUT/) {
*{__PACKAGE__ . '::' . lc($name)} = sub {
my $self = shift;
$self->start($self->build_tx($name, @_));
my $cb = (ref $_[-1] eq 'CODE') ? pop : undef;
$self->start($self->build_tx($name, @_), $cb);
};
}
}
Expand Down Expand Up @@ -88,7 +89,8 @@ sub need_proxy {

sub post_form {
my $self = shift;
$self->start($self->build_form_tx(@_));
my $cb = (ref $_[-1] eq 'CODE') ? pop : undef;
$self->start($self->build_form_tx(@_), $cb);
}

sub start {
Expand Down Expand Up @@ -125,7 +127,8 @@ sub start {

sub websocket {
my $self = shift;
$self->start($self->build_websocket_tx(@_));
my $cb = (ref $_[-1] eq 'CODE') ? pop : undef;
$self->start($self->build_websocket_tx(@_), $cb);
}

sub _cache {
Expand Down Expand Up @@ -228,7 +231,7 @@ sub _connect_proxy {

# Start CONNECT request
return unless my $new = $self->transactor->proxy_connect($old);
$self->_start(
return $self->_start(
$new => sub {
my ($self, $tx) = @_;

Expand Down Expand Up @@ -272,8 +275,6 @@ sub _connect_proxy {
$self->_start($old, $cb);
}
);

return 1;
}

sub _connected {
Expand Down
14 changes: 4 additions & 10 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -15,9 +15,6 @@ use Mojo::Util qw/encode url_escape/;
sub form {
my ($self, $url) = (shift, shift);

# Callback
my $cb = pop @_ if (ref $_[-1] || '') eq 'CODE';

# Form
my $encoding = shift;
my $form = ref $encoding ? $encoding : shift;
Expand Down Expand Up @@ -77,7 +74,7 @@ sub form {
$req->body($p->to_string);
}

return wantarray ? ($tx, $cb) : $tx;
return $tx;
}

# "This kid's a wonder!
Expand Down Expand Up @@ -165,25 +162,22 @@ sub tx {
$url = "http://$url" unless $url =~ m#^/|\://#;
ref $url ? $req->url($url) : $req->url->parse($url);

# Callback
my $cb = pop @_ if (ref $_[-1] || '') eq 'CODE';

# Body
$req->body(pop @_)
if @_ & 1 == 1 && ref $_[0] ne 'HASH' || ref $_[-2] eq 'HASH';

# Headers
$req->headers->from_hash(ref $_[0] eq 'HASH' ? $_[0] : {@_});

return wantarray ? ($tx, $cb) : $tx;
return $tx;
}

# "She found my one weakness... that I'm weak!"
sub websocket {
my $self = shift;

# New WebSocket
my ($tx, $cb) = $self->tx(GET => @_);
my $tx = $self->tx(GET => @_);
my $req = $tx->req;
my $abs = $req->url->to_abs;
if (my $scheme = $abs->scheme) {
Expand All @@ -194,7 +188,7 @@ sub websocket {
Mojo::Transaction::WebSocket->new(handshake => $tx, masked => 1)
->client_handshake;

return wantarray ? ($tx, $cb) : $tx;
return $tx;
}

sub _multipart {
Expand Down

0 comments on commit 149210c

Please sign in to comment.