Skip to content

Commit

Permalink
simplify include helper
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 4, 2014
1 parent 5fd40d7 commit 4119074
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -157,9 +157,9 @@ sub render {
my $maybe = delete $args->{'mojo.maybe'};

# Render
my $partial = $args->{partial};
my ($output, $format) = $app->renderer->render($self, $args);
return defined $output ? Mojo::ByteStream->new($output) : undef
if $args->{partial};
return defined $output ? Mojo::ByteStream->new($output) : undef if $partial;

# Maybe
return $maybe ? undef : !$self->render_not_found unless defined $output;
Expand Down Expand Up @@ -545,7 +545,7 @@ implements the following new ones.
$c->continue;
Continue dispatch chain.
Continue dispatch chain with L<Mojolicious::Routes/"continue">.
=head2 cookie
Expand Down
20 changes: 6 additions & 14 deletions lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -78,19 +78,15 @@ sub _current_route {
}

sub _include {
my $self = shift;
my $template = @_ % 2 ? shift : undef;
my $args = {@_, defined $template ? (template => $template) : ()};
my $self = shift;

# "layout" and "extends" can't be localized
my $layout = delete $args->{layout};
my $extends = delete $args->{extends};
# Template may be first argument
my ($template, $args) = (@_ % 2 ? shift : undef, {@_});
$args->{template} = $template if $template;

# Localize arguments
my @keys = keys %$args;
local @{$self->stash}{@keys} = @{$args}{@keys};

return $self->render(partial => 1, layout => $layout, extends => $extends);
local @{$self->stash}{keys %$args};
return $self->render(partial => 1, %$args);
}

sub _url_with {
Expand Down Expand Up @@ -146,10 +142,6 @@ if no preference could be detected.
$self->render(data => '', status => 204)
unless my $format = $self->accepts('html', 'json');
# List requested representations
my $formats = join(', ', @{$self->accepts}) || 'everything';
$self->app->log->debug("User agent wants $fortmats.");
=head2 app
%= app->secrets->[0]
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojolicious/Renderer.pm
Expand Up @@ -75,7 +75,8 @@ sub render {
my $stash = $c->stash;
local $stash->{layout} = $stash->{layout} if exists $stash->{layout};
local $stash->{extends} = $stash->{extends} if exists $stash->{extends};
delete @{$stash}{qw(layout extends)} if my $partial = $args->{partial};
delete @{$stash}{qw(layout extends)}
if my $partial = delete $args->{partial};

# Merge stash and arguments
@{$stash}{keys %$args} = values %$args;
Expand Down

0 comments on commit 4119074

Please sign in to comment.