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

sartak at bestpractical.com sartak at bestpractical.com
Tue Nov 4 17:36:35 EST 2008


Author: sartak
Date: Tue Nov  4 17:36:35 2008
New Revision: 16674

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm

Log:
 r74963 at onn:  sartak | 2008-11-03 22:49:24 -0500
 Make the Tokens type constraint do what I actually want it to; TODO: make it sane


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm	Tue Nov  4 17:36:35 2008
@@ -13,19 +13,21 @@
 #     - strings
 #     - regular expressions
 
-my $Str       = find_type_constraint('Str');
-my $RegexpRef = find_type_constraint('RegexpRef');
-my $ArrayRef  = find_type_constraint('ArrayRef');
-
-subtype 'Path::Dispatcher::Token'
-     => as 'Defined'
-     => where { $Str->check($_) || $RegexpRef->check($_) };
-
-subtype 'Path::Dispatcher::TokenAlternation'
-     => as 'ArrayRef[Path::Dispatcher::Token]';
+my $Str      = find_type_constraint('Str');
+my $Regex    = find_type_constraint('RegexpRef');
+my $ArrayRef = find_type_constraint('ArrayRef');
+
+my $Alternation;
+$Alternation = subtype as 'Defined'
+     => where {
+         return $Str->check($_) || $Regex->check($_) if ref($_) ne 'ARRAY';
+         $Alternation->check($_) or return for @$_;
+         1
+     };
 
 subtype 'Path::Dispatcher::Tokens'
-     => as 'ArrayRef[Path::Dispatcher::Token|Path::Dispatcher::TokenAlternation]';
+     => as 'ArrayRef'
+     => where { $Alternation->check($_) or return for @$_; 1 };
 
 has tokens => (
     is         => 'rw',
@@ -80,7 +82,7 @@
         ($got, $expected) = (lc $got, lc $expected) if !$self->case_sensitive;
         return $got eq $expected;
     }
-    elsif ($RegexpRef->check($expected)) {
+    elsif ($Regex->check($expected)) {
         return $got =~ $expected;
     }
     else {



More information about the Bps-public-commit mailing list