Initial support for :Args attribute
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Path.pm
index 1672712..ceea17b 100644 (file)
@@ -3,6 +3,7 @@ package Catalyst::DispatchType::Path;
 use strict;
 use base qw/Catalyst::DispatchType/;
 use Text::SimpleTable;
+use URI;
 
 =head1 NAME
 
@@ -25,7 +26,8 @@ sub list {
     my $paths = Text::SimpleTable->new( [ 36, 'Path' ], [ 37, 'Private' ] );
     for my $path ( sort keys %{ $self->{paths} } ) {
         my $action = $self->{paths}->{$path};
-        $paths->row( "/$path", "/$action" );
+        $path = "/$path" unless $path eq '/';
+        $paths->row( "$path", "/$action" );
     }
     $c->log->debug( "Loaded Path actions:\n" . $paths->draw )
       if ( keys %{ $self->{paths} } );
@@ -38,7 +40,9 @@ sub list {
 sub match {
     my ( $self, $c, $path ) = @_;
 
+    $path ||= '/';
     if ( my $action = $self->{paths}->{$path} ) {
+        return 0 unless $action->match($c);
         $c->req->action($path);
         $c->req->match($path);
         $c->action($action);
@@ -62,7 +66,7 @@ sub register {
     foreach my $r ( @{ $attrs->{Path} || [] } ) {
         unless ($r) {
             $r = $action->namespace;
-            $r = '' if $r eq '/';
+            $r = '/' unless length $r;
         }
         elsif ( $r !~ m!^/! ) {    # It's a relative path
             $r = $action->namespace . "/$r";
@@ -92,6 +96,8 @@ sub register {
 sub register_path {
     my ( $self, $c, $path, $action ) = @_;
     $path =~ s!^/!!;
+    $path = '/' unless length $path;
+    $path = URI->new($path)->canonical;
     $self->{paths}{$path} = $action;
 }