X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatchType%2FPath.pm;h=2cb950dac4f92db0e448fbf08eb1198f844a42ff;hb=640faa87f0c572b58acd22124bfa6f6c59106873;hp=67ea4113736d3d8608755ad9672db9638e82b1eb;hpb=784ab0e42f27feccdf30543d909352ae8657cbeb;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/DispatchType/Path.pm b/lib/Catalyst/DispatchType/Path.pm index 67ea411..2cb950d 100644 --- a/lib/Catalyst/DispatchType/Path.pm +++ b/lib/Catalyst/DispatchType/Path.pm @@ -2,7 +2,7 @@ package Catalyst::DispatchType::Path; use strict; use base qw/Catalyst::DispatchType/; -use Text::ASCIITable; +use Text::SimpleTable; =head1 NAME @@ -24,16 +24,13 @@ See L. sub list { my ( $self, $c ) = @_; - my $paths = Text::ASCIITable->new; - $paths->setCols( 'Path', 'Private' ); - $paths->setColWidth( 'Path', 36, 1 ); - $paths->setColWidth( 'Private', 37, 1 ); + my $paths = Text::SimpleTable->new( [ 36, 'Path' ], [ 37, 'Private' ] ); for my $path ( sort keys %{ $self->{paths} } ) { my $action = $self->{paths}->{$path}; - $paths->addRow( "/$path", "/$action" ); + $paths->row( "/$path", "/$action" ); } $c->log->debug( "Loaded Path actions:\n" . $paths->draw ) - if ( @{ $paths->{tbl_rows} } ); + if ( keys %{ $self->{paths} } ); } =item $self->match( $c, $path ) @@ -47,7 +44,7 @@ sub match { $c->req->action($path); $c->req->match($path); $c->action($action); - $c->namespace( $action->prefix ); + $c->namespace( $action->namespace ); return 1; } @@ -65,8 +62,12 @@ sub register { my @register; foreach my $r ( @{ $attrs->{Path} || [] } ) { - unless ( $r =~ m!^/! ) { # It's a relative path - $r = $action->prefix . "/$r"; + unless ($r) { + $r = $action->namespace; + $r = '' if $r eq '/'; + } + elsif ( $r !~ m!^/! ) { # It's a relative path + $r = $action->namespace . "/$r"; } push( @register, $r ); } @@ -76,15 +77,24 @@ sub register { } if ( $attrs->{Local} || $attrs->{Relative} ) { - push( @register, join( '/', $action->prefix, $action->name ) ); + push( @register, join( '/', $action->namespace, $action->name ) ); # Register sub name as a relative path } - foreach my $r (@register) { - $r =~ s!^/!!; - $self->{paths}{$r} = $action; - } + $self->register_path( $c, $_, $action ) for @register; + return 1 if @register; + return 0; +} + +=item $self->register_path($c, $path, $action) + +=cut + +sub register_path { + my ( $self, $c, $path, $action ) = @_; + $path =~ s!^/!!; + $self->{paths}{$path} = $action; } =back