Created
January 17, 2013 20:57
-
-
Save rkitover/4559690 to your computer and use it in GitHub Desktop.
merging captures into stash example
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
TEST HACK: | |
diff --git a/lib/Mojolicious/Routes.pm b/lib/Mojolicious/Routes.pm | |
index d6894c8..5ee7e9c 100644 | |
--- a/lib/Mojolicious/Routes.pm | |
+++ b/lib/Mojolicious/Routes.pm | |
@@ -223,8 +223,11 @@ sub _walk { | |
$staging--; | |
# Merge in captures | |
- my @keys = keys %$field; | |
- @{$stash}{@keys} = @{$stash->{'mojo.captures'}}{@keys} = values %$field; | |
+ while (my ($k, $v) = each %$field) { | |
+ $stash->{$k} = $v unless defined($stash->{$k}) && length($stash->{$k}) && ($v eq '' || (not defined $v)); | |
+ | |
+ $stash->{'mojo.captures'}{$k} = $v; | |
+ } | |
# Dispatch | |
my $continue | |
TESTS: | |
All tests successful. | |
Files=83, Tests=9333, 65 wallclock secs ( 2.22 usr 0.19 sys + 49.06 cusr 2.14 csys = 53.61 CPU) | |
Result: PASS | |
EXAMPLE BEHAVIOR TEST: | |
rkitover@amsems2wb-Stage ~/src/mojo % cat t/mojolicious/no_stash_override.t | |
use Mojo::Base -strict; | |
use Test::More; | |
use Mojolicious::Lite; | |
use Test::Mojo; | |
under '/' => sub { | |
my $c = shift; | |
$c->stash(foo => 'bar'); | |
return 1; | |
}; | |
get '/foo/*foo' => { foo => '' } => sub { | |
my $c = shift; | |
$c->render_text($c->stash('foo')); | |
}; | |
my $t = Test::Mojo->new; | |
$t->get_ok('/foo')->status_is(200)->content_is('bar'); | |
done_testing(); | |
RESULTS: | |
rkitover@amsems2wb-Stage ~/src/mojo % prove -wl t/mojolicious/no_stash_override.t | |
t/mojolicious/no_stash_override.t .. ok | |
All tests successful. | |
Files=1, Tests=3, 0 wallclock secs ( 0.05 usr 0.00 sys + 0.50 cusr 0.02 csys = 0.57 CPU) | |
Result: PASS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment