fixed bug with under block leaking its setting to following actions
Robert 'phaylon' Sedlacek [Thu, 20 Aug 2009 23:58:56 +0000 (01:58 +0200)]
Changes
lib/CatalystX/Declare/Keyword/Action.pm
t/110_under_sequence.t [new file with mode: 0644]
t/lib/TestApp/Controller/UnderSequence.pm [new file with mode: 0644]

diff --git a/Changes b/Changes
index ae2d81d..bd50c39 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,7 @@
       RenderView should now work with isa. (thanks to all reporters!)
     - documented 'isa' action class option (experimental!)
     - fixed bug where setup wasn't called without plugins
+    - fixed bug where under block scope wasn't cleaned up
 
 [0.008] Tue Aug 18 19:59:57 CEST 2009
     - default_inner now ignores arguments
index 2b52c9d..f29fab8 100644 (file)
@@ -16,6 +16,7 @@ class CatalystX::Declare::Keyword::Action
 
     use constant STOP_PARSING   => '__MXDECLARE_STOP_PARSING__';
     use constant UNDER_VAR      => '$CatalystX::Declare::SCOPE::UNDER';
+    use constant UNDER_STACK    => '@CatalystX::Declare::SCOPE::UNDER_STACK';
 
     use aliased 'CatalystX::Declare::Action::CatchValidationError';
     use aliased 'MooseX::Method::Signatures::Meta::Method';
@@ -272,8 +273,13 @@ class CatalystX::Declare::Keyword::Action
 
         if ($ctx->peek_next_char eq '{' and $self->identifier eq 'under') {
             $ctx->inject_if_block(
-                sprintf '%s; local %s; BEGIN { %s = qq(%s) };',
-                    $ctx->scope_injector_call,
+                sprintf '%s; BEGIN { push %s, %s; %s = qq(%s) };',
+                    $ctx->scope_injector_call(
+                        sprintf ';BEGIN { %s = pop %s };', 
+                            UNDER_VAR,
+                            UNDER_STACK,
+                    ),
+                    UNDER_STACK,
                     UNDER_VAR,
                     UNDER_VAR,
                     $target,
diff --git a/t/110_under_sequence.t b/t/110_under_sequence.t
new file mode 100644 (file)
index 0000000..e5d8253
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More; 
+use Catalyst::Test 'TestApp';
+
+is get('/under_seq/foo'), 'foo', 'basic action';
+is get('/under_seq/bar/test_bar'), 'bar', 'first action in under scope';
+is get('/under_seq/baz/test_baz'), 'baz', 'following base and under scope';
+
+done_testing;
+
+
diff --git a/t/lib/TestApp/Controller/UnderSequence.pm b/t/lib/TestApp/Controller/UnderSequence.pm
new file mode 100644 (file)
index 0000000..e5ba665
--- /dev/null
@@ -0,0 +1,19 @@
+use CatalystX::Declare;
+
+controller TestApp::Controller::UnderSequence {
+
+    action base under '/' as 'under_seq';
+
+    under base {
+
+        final action foo { $ctx->response->body('foo') }
+
+        action bar;
+
+        under bar { final action test_bar { $ctx->response->body('bar') } }
+
+        action baz;
+
+        under baz { final action test_baz { $ctx->response->body('baz') } }
+    }
+}