Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 8, 2013
1 parent d5ae666 commit 618e807
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/EventEmitter.pm
Expand Up @@ -16,7 +16,7 @@ sub emit {

if (my $s = $self->{events}{$name}) {
warn "-- Emit $name in @{[blessed($self)]} (@{[scalar(@$s)]})\n" if DEBUG;
for my $cb (@$s) { $self->$cb(@_) }
$self->$_(@_) for @$s;
}
elsif (DEBUG) { warn "-- Emit $name in @{[blessed($self)]} (0)\n" }

Expand Down
19 changes: 8 additions & 11 deletions lib/Mojolicious/Routes.pm
Expand Up @@ -14,17 +14,8 @@ has [qw(conditions shortcuts)] => sub { {} };
has hidden => sub { [qw(attr has new tap)] };
has namespaces => sub { [] };

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

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

sub auto_render {
my ($self, $c) = @_;
Expand Down Expand Up @@ -98,6 +89,12 @@ sub route {
shift->add_child(Mojolicious::Routes::Route->new(@_))->children->[-1];
}

sub _add {
my ($self, $attr, $name, $cb) = @_;
$self->$attr->{$name} = $cb;
return $self;
}

sub _callback {
my ($self, $c, $field, $staging) = @_;
$c->stash->{'mojo.routed'}++;
Expand Down

0 comments on commit 618e807

Please sign in to comment.