Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
small optimizations
  • Loading branch information
kraih committed Jan 8, 2013
1 parent d498d86 commit 3df3e35
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 40 deletions.
8 changes: 2 additions & 6 deletions lib/Mojo/Content/Single.pm
Expand Up @@ -9,7 +9,8 @@ has auto_upgrade => 1;

sub new {
my $self = shift->SUPER::new(@_);
$self->{read} = $self->on(read => \&_read);
$self->{read}
= $self->on(read => sub { $_[0]->asset($_[0]->asset->add_chunk($_[1])) });
return $self;
}

Expand Down Expand Up @@ -54,11 +55,6 @@ sub parse {
return $multi->parse;
}

sub _read {
my ($self, $chunk) = @_;
$self->asset($self->asset->add_chunk($chunk));
}

1;

=head1 NAME
Expand Down
8 changes: 2 additions & 6 deletions lib/Mojolicious.pm
Expand Up @@ -148,7 +148,8 @@ sub handler {
weaken $c->{$_} for qw(app tx);

# Dispatcher
++$self->{dispatch} and $self->hook(around_dispatch => \&_dispatch)
++$self->{dispatch}
and $self->hook(around_dispatch => sub { $_[1]->app->dispatch($_[1]) })
unless $self->{dispatch};

# Process
Expand Down Expand Up @@ -182,11 +183,6 @@ sub start { shift->commands->run(@_ ? @_ : @ARGV) }

sub startup { }

sub _dispatch {
my ($next, $c) = @_;
$c->app->dispatch($c);
}

sub _exception {
my ($next, $c) = @_;
local $SIG{__DIE__}
Expand Down
7 changes: 1 addition & 6 deletions lib/Mojolicious/Plugin/EPLRenderer.pm
Expand Up @@ -4,12 +4,7 @@ use Mojo::Base 'Mojolicious::Plugin';
use Mojo::Template;
use Mojo::Util qw(encode md5_sum);

sub register {
my ($self, $app) = @_;

# Add "epl" handler
$app->renderer->add_handler(epl => \&_epl);
}
sub register { $_[1]->renderer->add_handler(epl => \&_epl) }

sub _epl {
my ($renderer, $c, $output, $options) = @_;
Expand Down
7 changes: 2 additions & 5 deletions lib/Mojolicious/Plugin/EPRenderer.pm
Expand Up @@ -11,8 +11,8 @@ sub register {
# Auto escape by default to prevent XSS attacks
my $template = {auto_escape => 1, %{$conf->{template} || {}}};

# Add "ep" handler
$app->renderer->add_handler(
# Add "ep" handler and make it the default
$app->renderer->default_handler('ep')->add_handler(
$conf->{name} || 'ep' => sub {
my ($renderer, $c, $output, $options) = @_;

Expand Down Expand Up @@ -52,9 +52,6 @@ sub register {
return $renderer->handlers->{epl}->($renderer, $c, $output, $options);
}
);

# Set default handler
$app->renderer->default_handler('ep');
}

1;
Expand Down
25 changes: 8 additions & 17 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -23,8 +23,14 @@ $HOME->parse(
my %TEMPLATES = map { $_ => $HOME->slurp_rel_file($_) } @{$HOME->list_files};

sub new {
my $self = shift->SUPER::new(@_)->add_handler(json => \&_json);
return $self->add_handler(data => \&_data)->add_handler(text => \&_text);
my $self = shift->SUPER::new(@_);

$self->add_handler(
json => sub { ${$_[2]} = Mojo::JSON->new->encode($_[3]->{json}) });
$self->add_handler(data => sub { ${$_[2]} = $_[3]->{data} });
$self->add_handler(text => sub { ${$_[2]} = $_[3]->{text} });

return $self;
}

sub add_handler { shift->_add(handlers => @_) }
Expand Down Expand Up @@ -157,11 +163,6 @@ sub _add {

sub _bundled { $TEMPLATES{"@{[pop]}.html.ep"} }

sub _data {
my ($self, $c, $output, $options) = @_;
$$output = $options->{data};
}

sub _detect_handler {
my ($self, $options) = @_;

Expand Down Expand Up @@ -193,11 +194,6 @@ sub _extends {
return delete $stash->{extends};
}

sub _json {
my ($self, $c, $output, $options) = @_;
$$output = Mojo::JSON->new->encode($options->{json});
}

sub _render_template {
my ($self, $c, $output, $options) = @_;

Expand All @@ -213,11 +209,6 @@ sub _render_template {
return undef;
}

sub _text {
my ($self, $c, $output, $options) = @_;
$$output = $options->{text};
}

1;

=head1 NAME
Expand Down

0 comments on commit 3df3e35

Please sign in to comment.