[Bps-public-commit] r16389 - in Path-Dispatcher/trunk: lib/Path/Dispatcher/Rule t

sartak at bestpractical.com sartak at bestpractical.com
Mon Oct 20 08:02:28 EDT 2008


Author: sartak
Date: Mon Oct 20 08:02:27 2008
New Revision: 16389

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm
   Path-Dispatcher/trunk/t/012-under.t

Log:
 r74179 at onn:  sartak | 2008-10-20 08:02:22 -0400
 Require that the predicate of an under rule match just a prefix


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm	Mon Oct 20 08:02:27 2008
@@ -1,12 +1,18 @@
 #!/usr/bin/env perl
 package Path::Dispatcher::Rule::Under;
 use Moose;
+use Moose::Util::TypeConstraints;
 use MooseX::AttributeHelpers;
 extends 'Path::Dispatcher::Rule';
 
+subtype 'Path::Dispatcher::PrefixRule'
+     => as 'Path::Dispatcher::Rule'
+     => where { $_->prefix }
+     => message { "This rule ($_) does not match just prefixes!" };
+
 has predicate => (
     is  => 'rw',
-    isa => 'Path::Dispatcher::Rule',
+    isa => 'Path::Dispatcher::PrefixRule',
 );
 
 has _rules => (

Modified: Path-Dispatcher/trunk/t/012-under.t
==============================================================================
--- Path-Dispatcher/trunk/t/012-under.t	(original)
+++ Path-Dispatcher/trunk/t/012-under.t	Mon Oct 20 08:02:27 2008
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Test::More tests => 14;
+use Test::More tests => 15;
 use Path::Dispatcher;
 
 my $predicate = Path::Dispatcher::Rule::Tokens->new(
@@ -72,3 +72,16 @@
     $match = !$match if $data->{fail} && !$data->{catchall};
     ok($match, $name);
 }
+
+# ensure that the predicate MUST be a prefix
+eval {
+    local $SIG{__DIE__};
+
+    Path::Dispatcher::Rule::Under->new(
+        predicate => Path::Dispatcher::Rule::Tokens->new(
+            tokens => ['foo'],
+            prefix => 0,
+        ),
+    );
+};
+like($@, qr/Attribute \(predicate\) does not pass the type constraint because: This rule \(Path::Dispatcher::Rule::Tokens=HASH\(0x\w+\)\) does not match just prefixes!/, "predicate MUST match just a prefix");



More information about the Bps-public-commit mailing list