Created
August 29, 2009 10:14
-
-
Save shelling/177444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/Template.pm b/lib/Mojo/Template.pm | |
index b18ea02..2d81da2 100755 | |
--- a/lib/Mojo/Template.pm | |
+++ b/lib/Mojo/Template.pm | |
@@ -88,6 +88,15 @@ sub compile { | |
my $code = $self->code; | |
return unless $code; | |
+ my $c = shift; | |
+ my $declare_stash; | |
+ if (ref $c) { | |
+ for (keys %{$c->stash}) { | |
+ $declare_stash .= qq| my \$$_ = \$c->stash->{$_}; |; | |
+ } | |
+ } | |
+ $code = $declare_stash . $code if $declare_stash; | |
+ | |
# Compile | |
my $compiled = eval $code; | |
@@ -103,7 +112,7 @@ sub interpret { | |
# Compile | |
unless ($self->compiled) { | |
- my $e = $self->compile; | |
+ my $e = $self->compile(@_); | |
# Exception | |
return $e if ref $e; | |
@@ -272,7 +281,7 @@ sub render { | |
$self->build; | |
# Compile | |
- my $e = $self->compile; | |
+ my $e = $self->compile(@_); | |
return $e if $e; | |
# Interpret | |
diff --git a/t/mojolicious/app.t b/t/mojolicious/app.t | |
index 2645a63..fd43133 100644 | |
--- a/t/mojolicious/app.t | |
+++ b/t/mojolicious/app.t | |
@@ -5,7 +5,7 @@ | |
use strict; | |
use warnings; | |
-use Test::More tests => 113; | |
+use Test::More tests => 115; | |
use FindBin; | |
use lib "$FindBin::Bin/lib"; | |
@@ -279,3 +279,9 @@ is($tx->res->code, 200); | |
is($tx->res->headers->server, 'Mojo (Perl)'); | |
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)'); | |
is($tx->res->body, 'Go away!'); | |
+ | |
+# MojoliciousTestController::Foo::brief_stash_var_name | |
+$tx = Mojo::Transaction::Single->new_get('/foo/brief_stash_var_name'); | |
+$client->process_app('MojoliciousTest', $tx); | |
+is($tx->res->code, 200); | |
+is($tx->res->body, "shelling\nshelling\@cpan.org\n"); | |
diff --git a/t/mojolicious/lib/MojoliciousTest/Foo.pm b/t/mojolicious/lib/MojoliciousTest/Foo.pm | |
index fa7e128..1f67c38 100644 | |
--- a/t/mojolicious/lib/MojoliciousTest/Foo.pm | |
+++ b/t/mojolicious/lib/MojoliciousTest/Foo.pm | |
@@ -54,4 +54,11 @@ sub willdie { die 'for some reason' } | |
sub withlayout { shift->stash(template => 'withlayout') } | |
+sub brief_stash_var_name { | |
+ shift->render( | |
+ name => "shelling", | |
+ email => 'shelling@cpan.org', | |
+ ); | |
+} | |
+ | |
1; | |
diff --git a/t/mojolicious/templates/foo/brief_stash_var_name.html.epl b/t/mojolicious/templates/foo/brief_stash_var_name.html.epl | |
new file mode 100644 | |
index 0000000..aabd3e5 | |
--- /dev/null | |
+++ b/t/mojolicious/templates/foo/brief_stash_var_name.html.epl | |
@@ -0,0 +1,2 @@ | |
+<%= $name %> | |
+<%= $email %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment