[Bps-public-commit] Path-Dispatcher branch, master, updated. 1230d483aa7a04ba73cc009ac77ebb14cbd9213e

Shawn Moore sartak at bestpractical.com
Fri Mar 4 20:14:09 EST 2011


The branch, master has been updated
       via  1230d483aa7a04ba73cc009ac77ebb14cbd9213e (commit)
      from  7f199668c19c461accaf188292562d682615adba (commit)

Summary of changes:
 t/027-custom-named-captures.t |   52 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)
 create mode 100644 t/027-custom-named-captures.t

- Log -----------------------------------------------------------------
commit 1230d483aa7a04ba73cc009ac77ebb14cbd9213e
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Fri Mar 4 20:13:34 2011 -0500

    Add a test demonstrating custom populating of named_captures

diff --git a/t/027-custom-named-captures.t b/t/027-custom-named-captures.t
new file mode 100644
index 0000000..da91855
--- /dev/null
+++ b/t/027-custom-named-captures.t
@@ -0,0 +1,52 @@
+use strict;
+use warnings;
+use Test::More;
+use Path::Dispatcher;
+
+{
+    package My::Rule::NamedEnum;
+    use Any::Moose;
+    extends 'Path::Dispatcher::Rule';
+
+    has name => (
+        is       => 'ro',
+        isa      => 'Str',
+        required => 1,
+    );
+
+    has regex => (
+        is       => 'ro',
+        isa      => 'RegexpRef',
+        required => 1,
+    );
+
+    sub _match {
+        my $self = shift;
+        my $path = shift;
+
+        return unless $path =~ $self->regex;
+
+        return {
+            named_captures => {
+                $self->name => $&,
+            },
+        };
+    }
+}
+
+my $dispatcher = Path::Dispatcher->new(
+    rules => [
+        My::Rule::NamedEnum->new(
+            name  => 'hoo-ah',
+            regex => qr/^\w+::/,
+            block => sub { shift },
+        )
+    ],
+);
+
+my $match = $dispatcher->run("Foo::Bar");
+is_deeply($match->positional_captures, []);
+is_deeply($match->named_captures, { "hoo-ah" => "Foo::" });
+
+done_testing;
+

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



More information about the Bps-public-commit mailing list