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

sartak at bestpractical.com sartak at bestpractical.com
Wed Aug 13 05:09:22 EDT 2008


Author: sartak
Date: Wed Aug 13 05:09:14 2008
New Revision: 15109

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

Log:
 r69451 at onn:  sartak | 2008-08-13 05:08:22 -0400
 Remove the logic in Rule that is controlled by subclasses


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm	Wed Aug 13 05:09:14 2008
@@ -9,12 +9,6 @@
     required => 1,
 );
 
-has matcher => (
-    is       => 'ro',
-    isa      => 'CodeRef',
-    required => 1,
-);
-
 has block => (
     is       => 'ro',
     isa      => 'CodeRef',
@@ -31,39 +25,11 @@
     },
 );
 
-around BUILDARGS => sub {
-    my $orig = shift;
-    my $self = shift;
-    my $args = $self->$orig(@_);
-
-    if (!$args->{matcher} && $args->{regex}) {
-        $args->{matcher} = $self->build_regex_matcher(delete $args->{regex});
-    }
-
-    return $args;
-};
-
-sub build_regex_matcher {
-    my $self = shift;
-    my $re   = shift;
-
-    # compile the regex immediately, instead of each match
-    $re = qr/$re/;
-
-    return sub {
-        return unless $_ =~ $re;
-
-        my $path = $_;
-        return [ map { substr($path, $-[$_], $+[$_] - $-[$_]) } 1 .. $#- ];
-    }
-}
-
 sub match {
     my $self = shift;
     my $path = shift;
 
-    local $_ = $path;
-    my $result = $self->matcher->();
+    my $result = $self->_match($path);
     return unless $result;
 
     # make sure that the returned values are PLAIN STRINGS
@@ -89,5 +55,10 @@
 __PACKAGE__->meta->make_immutable;
 no Moose;
 
+# don't require others to load our subclasses explicitly
+require Path::Dispatcher::Rule::CodeRef;
+require Path::Dispatcher::Rule::Regex;
+require Path::Dispatcher::Rule::Tokens;
+
 1;
 



More information about the Bps-public-commit mailing list