Skip to content

Commit

Permalink
the default handlers do not serve a purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 8, 2016
1 parent cf21545 commit b7a08c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@
- Deprecated Mojo::Server::Morbo::check in favor of
Mojo::Server::Morbo::modified_files. (leejo, nugged)
- Added modified_files method to Mojo::Server::Morbo. (leejo, nugged)
- Improved renderer performance slightly.
- Fixed a bug where Morbo would restart more than once if multiple files
changed at the same time. (leejo, nugged)

Expand Down
32 changes: 7 additions & 25 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -13,9 +13,8 @@ has classes => sub { ['main'] };
has default_format => 'html';
has 'default_handler';
has encoding => 'UTF-8';
has handlers => sub { {data => \&_data, json => \&_json, text => \&_text} };
has helpers => sub { {} };
has paths => sub { [] };
has [qw(handlers helpers)] => sub { {} };
has paths => sub { [] };

# Bundled templates
my $TEMPLATES = Mojo::Home->new(Mojo::Home->new->mojo_lib_dir)
Expand Down Expand Up @@ -98,26 +97,16 @@ sub render {
$options->{format} = $stash->{format} || $self->default_format;

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

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

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

# Template or templateless handler
else {
unless (defined $output) {
$options->{template} //= $self->template_for($c);
return () unless $self->_render_template($c, \$output, $options);
}
Expand Down Expand Up @@ -206,10 +195,6 @@ sub warmup {
}
}

sub _data { ${$_[2]} = $_[3]{data} }

sub _json { ${$_[2]} = encode_json($_[3]{json}) }

sub _next {
my $stash = shift;
return delete $stash->{extends} if $stash->{extends};
Expand All @@ -229,8 +214,6 @@ sub _render_template {
return 1 if defined $$output;
}

sub _text { ${$_[2]} = $_[3]{text} }

1;

=encoding utf8
Expand Down Expand Up @@ -312,8 +295,7 @@ determine if template files should be decoded before processing.
my $handlers = $renderer->handlers;
$renderer = $renderer->handlers({epl => sub {...}});
Registered handlers, by default only C<data>, C<text> and C<json> are already
defined.
Registered handlers.
=head2 helpers
Expand Down

0 comments on commit b7a08c3

Please sign in to comment.