add %_ setting
Matt S Trout [Wed, 2 May 2012 16:58:47 +0000 (16:58 +0000)]
Changes
lib/Web/Simple/DispatchNode.pm
t/underscore.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index a12cb72..097df8b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,4 @@
+  - Add %_ alias if first argument is a hashref
   - Un-mark upload matches as experimental since they work
 
 0.018 - 2012-07-15
index 36e5e67..3f37c05 100644 (file)
@@ -9,7 +9,10 @@ has _app_object => (is => 'ro', init_arg => 'app_object', required => 1);
 # this ensures that the dispatchers get called as methods of the app itself
 around _curry => sub {
   my ($orig, $self) = (shift, shift);
-  $self->$orig($self->_app_object, @_);
+  my $code = $self->$orig($self->_app_object, @_);
+  ref($_[0]) eq 'HASH'
+    ? do { my $v = $_[0]; sub { local *_ = $v; &$code } }
+    : $code
 };
 
 1;
diff --git a/t/underscore.t b/t/underscore.t
new file mode 100644 (file)
index 0000000..7252582
--- /dev/null
@@ -0,0 +1,14 @@
+use Web::Simple 'TestApp';
+use Test::More;
+
+sub TestApp::dispatch_request {
+  sub (GET + ?*) {
+    [ 200, [ 'Content-type' => 'text/plain' ], [ $_{foo} ] ]
+  }
+}
+
+my $res = TestApp->new->run_test_request(GET => '/?foo=bar');
+
+is($res->content, 'bar', '%_ set ok');
+
+done_testing;