[Bps-public-commit] Path-Dispatcher branch, named_captures, updated. de83e4fafc4f77b813f7d26fadc91b980ff2991f

Shawn Moore sartak at bestpractical.com
Thu Jun 24 15:44:57 EDT 2010


The branch, named_captures has been updated
       via  de83e4fafc4f77b813f7d26fadc91b980ff2991f (commit)
       via  855cd67a3c19f392bf8dd770c9351dbe7d2b7b88 (commit)
      from  293783a9b46025707533ca785e0356f157b46ad2 (commit)

Summary of changes:
 lib/Path/Dispatcher/Match.pm       |    2 +-
 lib/Path/Dispatcher/Rule/Tokens.pm |   16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

- Log -----------------------------------------------------------------
commit 855cd67a3c19f392bf8dd770c9351dbe7d2b7b88
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Jun 24 15:45:08 2010 -0400

    Captures are in %+ not %%

diff --git a/lib/Path/Dispatcher/Match.pm b/lib/Path/Dispatcher/Match.pm
index 1dbe143..c0920b9 100644
--- a/lib/Path/Dispatcher/Match.pm
+++ b/lib/Path/Dispatcher/Match.pm
@@ -58,7 +58,7 @@ sub _run_with_capture_vars {
     *{ ++$i } = \$_ for @{ $self->positional_captures };
 
     # populate %+
-    *% = $self->named_captures;
+    *+ = $self->named_captures;
 
     $code->();
 }

commit de83e4fafc4f77b813f7d26fadc91b980ff2991f
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Jun 24 15:45:27 2010 -0400

    Thread the results of %+ up through to the Match

diff --git a/lib/Path/Dispatcher/Rule/Tokens.pm b/lib/Path/Dispatcher/Rule/Tokens.pm
index ad98c13..19eac43 100644
--- a/lib/Path/Dispatcher/Rule/Tokens.pm
+++ b/lib/Path/Dispatcher/Rule/Tokens.pm
@@ -22,8 +22,9 @@ has case_sensitive => (
 );
 
 sub _match_as_far_as_possible {
-    my $self = shift;
-    my $path = shift;
+    my $self  = shift;
+    my $path  = shift;
+    my $named = shift;
 
     my @got      = $self->tokenize($path->path);
     my @expected = $self->tokens;
@@ -33,7 +34,7 @@ sub _match_as_far_as_possible {
         my $expected = $expected[0];
         my $got      = $got[0];
 
-        last unless $self->_match_token($got, $expected);
+        last unless $self->_match_token($got, $expected, $named);
 
         push @matched, $got;
         shift @expected;
@@ -47,7 +48,9 @@ sub _match {
     my $self = shift;
     my $path = shift;
 
-    my ($matched, $got, $expected) = $self->_match_as_far_as_possible($path);
+    my $named = {};
+
+    my ($matched, $got, $expected) = $self->_match_as_far_as_possible($path, $named);
 
     return if @$expected; # didn't provide everything necessary
     return if @$got && !$self->prefix; # had tokens left over
@@ -55,7 +58,8 @@ sub _match {
     my $leftover = $self->untokenize(@$got);
     return {
         positional_captures => $matched,
-        leftover => $leftover,
+        named_captures      => $named,
+        leftover            => $leftover,
     };
 }
 
@@ -104,6 +108,7 @@ sub _match_token {
     my $self     = shift;
     my $got      = shift;
     my $expected = shift;
+    my $named    = shift;
 
     my $matched = 0;
     $self->_each_token($got, $expected, sub {
@@ -114,6 +119,7 @@ sub _match_token {
         }
         elsif (ref($e) eq 'Regexp') {
             $matched ||= $g =~ $e;
+            @$named{keys %+} = values %+;
         }
     });
 

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



More information about the Bps-public-commit mailing list