Skip to content
Browse files

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

  • Loading branch information...
1 parent fe8e72d commit d81a1a99198bdcd46bc62fe6709396ebcb0fa4b7 @sartak sartak committed
Showing with 18 additions and 0 deletions.
  1. +18 −0 lib/Path/Dispatcher/Declarative/Builder.pm
View
18 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);
}

0 comments on commit d81a1a9

Please sign in to comment.
Something went wrong with that request. Please try again.