[Bps-public-commit] path-dispatcher-declarative branch, master, updated. d81a1a99198bdcd46bc62fe6709396ebcb0fa4b7

Shawn Moore sartak at bestpractical.com
Sun Oct 24 03:29:57 EDT 2010


The branch, master has been updated
       via  d81a1a99198bdcd46bc62fe6709396ebcb0fa4b7 (commit)
      from  fe8e72dd7ee5d4e51c766e6ef8c91fafdbd2b8ba (commit)

Summary of changes:
 lib/Path/Dispatcher/Declarative/Builder.pm |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

- Log -----------------------------------------------------------------
commit d81a1a99198bdcd46bc62fe6709396ebcb0fa4b7
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Sun Oct 24 16:29:57 2010 +0900

    Set $1, $2, $3 from the match in Declarative

diff --git a/lib/Path/Dispatcher/Declarative/Builder.pm b/lib/Path/Dispatcher/Declarative/Builder.pm
index 07400e3..57ea62d 100644
--- a/lib/Path/Dispatcher/Declarative/Builder.pm
+++ b/lib/Path/Dispatcher/Declarative/Builder.pm
@@ -220,6 +220,24 @@ sub _add_rule {
     }
     else {
         my ($matcher, $block) = splice @_, 0, 2;
+
+        # set $1, etc
+        my $old_block = $block;
+        $block = sub {
+            my $match = shift;
+
+            # clear $1, $2, $3 so they don't pollute the number vars for the block
+            "x" =~ /x/;
+
+            # populate $1, $2, etc for the duration of $code
+            # it'd be nice if we could use "local" but it seems to break tests
+            my $i = 0;
+            no strict 'refs';
+            *{ ++$i } = \$_ for @{ $match->positional_captures };
+
+            $old_block->(@_);
+        };
+
         $rule = $self->_create_rule($matcher, block => $block);
     }
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list