Skip to content

Commit

Permalink
rename run method to process
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 6, 2016
1 parent 136a138 commit 954a652
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Changes
@@ -1,11 +1,11 @@

6.54 2016-03-06
- Deprecated Mojo::Template::interpret in favor of Mojo::Template::run.
- Deprecated Mojo::Template::interpret in favor of Mojo::Template::process.
- Deprecated Mojo::Template::build.
- Deprecated Mojo::Template::compile.
- Added support for named variables to Mojo::Template.
- Added vars attribute to Mojo::Template.
- Added run method to Mojo::Template.
- Added process method to Mojo::Template.
- Improved Mojo::Template performance slightly.

6.53 2016-03-03
Expand Down
64 changes: 32 additions & 32 deletions lib/Mojo/Template.pm
Expand Up @@ -38,8 +38,8 @@ sub compile {
# DEPRECATED!
sub interpret {
deprecated 'Mojo::Template::compile is DEPRECATED'
. ' in favor of Mojo::Template::run';
shift->run(@_);
. ' in favor of Mojo::Template::process';
shift->process(@_);
}

sub parse {
Expand Down Expand Up @@ -157,21 +157,7 @@ sub parse {
return $self;
}

sub render { shift->parse(shift)->run(@_) }

sub render_file {
my ($self, $path) = (shift, shift);

$self->name($path) unless defined $self->{name};
my $template = slurp $path;
my $encoding = $self->encoding;
croak qq{Template "$path" has invalid encoding}
if $encoding && !defined($template = decode $encoding, $template);

return $self->render($template, @_);
}

sub run {
sub process {
my $self = shift;

if (!$self->{compiled} && (my $e = $self->_build->_compile(@_))) { return $e }
Expand All @@ -187,6 +173,20 @@ sub run {
return eval { $output = $self->compiled->(@_); 1 } ? $output : $@;
}

sub render { shift->parse(shift)->process(@_) }

sub render_file {
my ($self, $path) = (shift, shift);

$self->name($path) unless defined $self->{name};
my $template = slurp $path;
my $encoding = $self->encoding;
croak qq{Template "$path" has invalid encoding}
if $encoding && !defined($template = decode $encoding, $template);

return $self->render($template, @_);
}

sub _build {
my $self = shift;

Expand Down Expand Up @@ -660,6 +660,20 @@ following new ones.
Parse template into L</"tree">.
=head2 process
my $output = $mt->process;
my $output = $mt->process(@args);
my $output = $mt->process({foo => 'bar'});
Process template code and return the result, or a L<Mojo::Exception> object if
rendering failed.
# Reuse template
say $mt->render('Hello <%= $_[0] %>!', 'Bender');
say $mt->process('Fry');
say $mt->process('Leela');
=head2 render
my $output = $mt->render('<%= 1 + 1 %>');
Expand All @@ -670,7 +684,7 @@ Render template and return the result, or a L<Mojo::Exception> object if
rendering failed.
# Longer version
my $output = $mt->parse('<%= 1 + 1 %>')->run;
my $output = $mt->parse('<%= 1 + 1 %>')->process;
# Render with arguments
say Mojo::Template->new->render('<%= $_[0] %>', 'bar');
Expand All @@ -686,20 +700,6 @@ rendering failed.
Same as L</"render">, but renders a template file.
=head2 run
my $output = $mt->run;
my $output = $mt->run(@args);
my $output = $mt->run({foo => 'bar'});
Run template code and return the result, or a L<Mojo::Exception> object if
rendering failed.
# Reuse template
say $mt->render('Hello <%= $_[0] %>!', 'Bender');
say $mt->run('Fry');
say $mt->run('Leela');
=head1 DEBUGGING
You can set the C<MOJO_TEMPLATE_DEBUG> environment variable to get some
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/EPLRenderer.pm
Expand Up @@ -16,7 +16,7 @@ sub _render {
# Cached
if ($mt->compiled) {
$c->app->log->debug("Rendering cached @{[$mt->name]}");
$$output = $mt->run(@args);
$$output = $mt->process(@args);
}

# Not cached
Expand Down
6 changes: 3 additions & 3 deletions t/mojo/template.t
Expand Up @@ -810,9 +810,9 @@ $output = $mt->render(<<'EOF', 'test', {foo => 'bar'});
</html>
EOF
is $output, "<html>\ntest bar\n</html>\n", 'arguments';
is $mt->run('tset', {foo => 'baz'}), "<html>\ntset baz\n</html>\n",
is $mt->process('tset', {foo => 'baz'}), "<html>\ntset baz\n</html>\n",
'arguments again';
is $mt->run('tset', {foo => 'yada'}), "<html>\ntset yada\n</html>\n",
is $mt->process('tset', {foo => 'yada'}), "<html>\ntset yada\n</html>\n",
'arguments again';

# Variables
Expand Down Expand Up @@ -1063,7 +1063,7 @@ test
321
EOF
is $mt->tree->[0][1], "test\n123\n456", 'optimized text lines';
$output = $mt->run;
$output = $mt->process;
is_deeply $mt->tree, [], 'has been consumed';
is $output, "test\n123\n456789\\\n987\n654\n321\n", 'just text';

Expand Down

0 comments on commit 954a652

Please sign in to comment.