Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
small optimizations
  • Loading branch information
kraih committed Sep 4, 2012
1 parent 67fab50 commit 0372fb5
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 19 deletions.
5 changes: 2 additions & 3 deletions lib/Mojo/Asset/Memory.pm
Expand Up @@ -15,10 +15,9 @@ sub add_chunk {
$self->{content} .= $chunk // '';
return $self
if !$self->auto_upgrade || $self->size <= $self->max_memory_size;
my $file = Mojo::Asset::File->new;
$self->emit(upgrade => $file);

return $file->add_chunk($self->slurp);
my $file = Mojo::Asset::File->new;
return $file->add_chunk($self->emit(upgrade => $file)->slurp);
}

sub contains {
Expand Down
5 changes: 1 addition & 4 deletions lib/Mojo/EventEmitter.pm
Expand Up @@ -65,10 +65,7 @@ sub unsubscribe {
my ($self, $name, $cb) = @_;

# All
unless ($cb) {
delete $self->{events}{$name};
return $self;
}
return $self->tap(sub { delete $_->{events}{$name} }) unless $cb;

# One
$self->{events}{$name} = [grep { $cb ne $_ } @{$self->{events}{$name}}];
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/Exception.pm
Expand Up @@ -105,8 +105,7 @@ sub _detect {
for my $frame (reverse @trace) {
next unless -r $frame->[0];
open my $handle, '<:utf8', $frame->[0];
$self->_context($frame->[1], [[<$handle>]]);
return $self;
return $self->tap(sub { $_->_context($frame->[1], [[<$handle>]]) });
}

# More context
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -26,6 +26,7 @@ sub endpoint {
# Proxy for normal HTTP requests
return $self->_proxy($tx, $scheme, $host, $port)
if $scheme eq 'http' && lc($req->headers->upgrade || '') ne 'websocket';

return $scheme, $host, $port;
}

Expand Down
6 changes: 2 additions & 4 deletions lib/Mojolicious/Routes.pm
Expand Up @@ -16,14 +16,12 @@ has 'namespace';

sub add_condition {
my ($self, $name, $cb) = @_;
$self->conditions->{$name} = $cb;
return $self;
return $self->tap(sub { $_->conditions->{$name} = $cb });
}

sub add_shortcut {
my ($self, $name, $cb) = @_;
$self->shortcuts->{$name} = $cb;
return $self;
return $self->tap(sub { $_->shortcuts->{$name} = $cb });
}

sub auto_render {
Expand Down
9 changes: 3 additions & 6 deletions lib/Test/Mojo.pm
Expand Up @@ -9,7 +9,6 @@ use Mojo::Base -base;
# Bender: You're better off dead, I'm telling you, dude.
# Fry: Santa Claus is gunning you down!"
use Mojo::IOLoop;
use Mojo::Message::Response;
use Mojo::Server;
use Mojo::UserAgent;
use Mojo::Util qw(decode encode);
Expand Down Expand Up @@ -191,8 +190,7 @@ sub options_ok { shift->_request_ok(options => @_) }

sub or {
my ($self, $cb) = @_;
$self->$cb unless $self->{latest};
return $self;
return $self->tap(sub { $_->{latest} or $_->$cb });
}

sub patch_ok { shift->_request_ok(patch => @_) }
Expand Down Expand Up @@ -310,10 +308,9 @@ sub _request_ok {
}

sub _test {
my ($self, $name) = (shift, shift);
my ($self, $name, @args) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 2;
$self->{latest} = Test::More->can($name)->(@_);
return $self;
return $self->tap(sub { $_->{latest} = Test::More->can($name)->(@args) });
}

sub _text {
Expand Down

0 comments on commit 0372fb5

Please sign in to comment.