Navigation Menu

Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 10, 2013
1 parent 0f3f6d8 commit 9ef3b05
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -71,41 +71,37 @@ sub render {
handler => $stash->{handler},
template => delete $stash->{template}
};
my $data = delete $stash->{data};
my $json = delete $stash->{json};
my $inline = $options->{inline} = delete $stash->{inline};
$options->{format} = $stash->{format} || $self->default_format;
$options->{handler} //= $self->default_handler if defined $inline;

# Text
my $output;
if (defined(my $text = delete $stash->{text})) {
$self->handlers->{text}->($self, $c, \$output, {text => $text});
}
$options->{format} = $stash->{format} || $self->default_format;

# Data
elsif (defined $data) {
my $output;
if (defined(my $data = delete $stash->{data})) {
$self->handlers->{data}->($self, $c, \$output, {data => $data});
return $output, $options->{format};
}

# JSON
elsif (defined $json) {
elsif (my $json = delete $stash->{json}) {
$self->handlers->{json}->($self, $c, \$output, {json => $json});
$options->{format} = 'json';
return $output, 'json';
}

# Text
elsif (defined(my $text = delete $stash->{text})) {
$self->handlers->{text}->($self, $c, \$output, {text => $text});
}

# Template or templateless handler
else { return unless $self->_render_template($c, \$output, $options) }

# Data and JSON can't be extended
return $output, $options->{format} if defined $data || $json;

# Extends
my $content = $stash->{'mojo.content'} ||= {};
$content->{content} = $output if $stash->{extends} || $stash->{layout};
local $content->{content} = $output if $stash->{extends} || $stash->{layout};
while ((my $extends = $self->_extends($stash)) && !defined $inline) {
$options->{format} = $stash->{format} || $self->default_format;
$options->{handler} = $stash->{handler};
$options->{format} = $stash->{format} || $self->default_format;
$options->{template} = $extends;
$self->_render_template($c, \$output, $options);
$content->{content} = $output
Expand Down

0 comments on commit 9ef3b05

Please sign in to comment.