Looping and recursion tests plus a fix
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Path.pm
index 227815f..bd74c79 100644 (file)
@@ -3,6 +3,7 @@ package Catalyst::DispatchType::Path;
 use strict;
 use base qw/Catalyst::DispatchType/;
 use Text::SimpleTable;
+use URI;
 
 =head1 NAME
 
@@ -41,6 +42,7 @@ sub match {
 
     $path ||= '/';
     if ( my $action = $self->{paths}->{$path} ) {
+        return 0 unless $action->match($c);
         $c->req->action($path);
         $c->req->match($path);
         $c->action($action);
@@ -58,31 +60,10 @@ sub match {
 sub register {
     my ( $self, $c, $action ) = @_;
 
-    my $attrs = $action->attributes;
-    my @register;
-
-    foreach my $r ( @{ $attrs->{Path} || [] } ) {
-        unless ($r) {
-            $r = $action->namespace;
-            $r = '/' unless length $r;
-        }
-        elsif ( $r !~ m!^/! ) {    # It's a relative path
-            $r = $action->namespace . "/$r";
-        }
-        push( @register, $r );
-    }
-
-    if ( $attrs->{Global} || $attrs->{Absolute} ) {
-        push( @register, $action->name );    # Register sub name against root
-    }
-
-    if ( $attrs->{Local} || $attrs->{Relative} ) {
-        push( @register, join( '/', $action->namespace, $action->name ) );
-
-        # Register sub name as a relative path
-    }
+    my @register = @{ $action->attributes->{Path} || [] };
 
     $self->register_path( $c, $_, $action ) for @register;
+
     return 1 if @register;
     return 0;
 }
@@ -95,6 +76,8 @@ sub register_path {
     my ( $self, $c, $path, $action ) = @_;
     $path =~ s!^/!!;
     $path = '/' unless length $path;
+    $path = URI->new($path)->canonical;
+
     $self->{paths}{$path} = $action;
 }