Fixed Path and index actions in the appclass
Sebastian Riedel [Fri, 2 Dec 2005 01:55:51 +0000 (01:55 +0000)]
Changes
lib/Catalyst/DispatchType/Path.pm
lib/Catalyst/Dispatcher.pm
lib/Catalyst/Manual/Intro.pod

diff --git a/Changes b/Changes
index 34e247e..db71005 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,9 @@
 This file documents the revision history for Perl extension Catalyst.
 
 5.60
+        - Fixed Path and index actions in the appclass,
+          including those that attach to /
+        - Index is now weighted higher than Path
         - Fixed restarter and -d debug switch in server.pl.
         - Added a warning if you attempt to retrieve a parameter
           using $c->req->params('foo').
index 1672712..98ef303 100644 (file)
@@ -25,7 +25,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,6 +39,7 @@ sub list {
 sub match {
     my ( $self, $c, $path ) = @_;
 
+    $path ||= '/';
     if ( my $action = $self->{paths}->{$path} ) {
         $c->req->action($path);
         $c->req->match($path);
@@ -62,7 +64,7 @@ sub register {
     foreach my $r ( @{ $attrs->{Path} || [] } ) {
         unless ($r) {
             $r = $action->namespace;
-            $r = '' if $r eq '/';
+            $r = '/' unless $r;
         }
         elsif ( $r !~ m!^/! ) {    # It's a relative path
             $r = $action->namespace . "/$r";
@@ -92,6 +94,7 @@ sub register {
 sub register_path {
     my ( $self, $c, $path, $action ) = @_;
     $path =~ s!^/!!;
+    $path = '/' unless $path;
     $self->{paths}{$path} = $action;
 }
 
index 4ceea4c..8c4a5d8 100644 (file)
@@ -21,10 +21,10 @@ __PACKAGE__->mk_accessors(
 );
 
 # Preload these action types
-our @PRELOAD = qw/Path Regex/;
+our @PRELOAD = qw/Index Path Regex/;
 
 # Postload these action types
-our @POSTLOAD = qw/Index Default/;
+our @POSTLOAD = qw/Default/;
 
 =head1 NAME
 
@@ -178,12 +178,13 @@ sub prepare_action {
     my @path = split /\//, $c->req->path;
     $c->req->args( \my @args );
 
-    push( @path, '/' ) unless @path;    # Root action
+    unshift( @path, '' );    # Root action
 
   DESCEND: while (@path) {
         $path = join '/', @path;
+        $path =~ s#^/##;
 
-        $path = '' if $path eq '/';     # Root action
+        $path = '' if $path eq '/';    # Root action
 
         # Check out dispatch types to see if any will handle the path at
         # this level
index 2f78233..e8b1c86 100644 (file)
@@ -448,7 +448,7 @@ controller it's in.
 C<index> is much like C<default> except that it takes no arguments
 and it is weighted slightly higher in the matching process. It is
 useful as a static entry point to a controller, e.g. to have a static
-welcome page.
+welcome page. Note that it's also weighted higher than Path.
 
 =item * B<begin : Private>