1 package Catalyst::DispatchType::Path;
4 use base qw/Catalyst::DispatchType/;
10 Catalyst::DispatchType::Path - Path DispatchType
20 =head2 $self->list($c)
25 my ( $self, $c ) = @_;
26 my $paths = Text::SimpleTable->new( [ 36, 'Path' ], [ 37, 'Private' ] );
27 for my $path ( sort keys %{ $self->{paths} } ) {
28 my $action = $self->{paths}->{$path};
29 $path = "/$path" unless $path eq '/';
30 $paths->row( "$path", "/$action" );
32 $c->log->debug( "Loaded Path actions:\n" . $paths->draw )
33 if ( keys %{ $self->{paths} } );
36 =head2 $self->match( $c, $path )
41 my ( $self, $c, $path ) = @_;
44 if ( my $action = $self->{paths}->{$path} ) {
45 $c->req->action($path);
46 $c->req->match($path);
48 $c->namespace( $action->namespace );
55 =head2 $self->register( $c, $action )
60 my ( $self, $c, $action ) = @_;
62 my $attrs = $action->attributes;
65 foreach my $r ( @{ $attrs->{Path} || [] } ) {
67 $r = $action->namespace;
68 $r = '/' unless length $r;
70 elsif ( $r !~ m!^/! ) { # It's a relative path
71 $r = $action->namespace . "/$r";
73 push( @register, $r );
76 if ( $attrs->{Global} || $attrs->{Absolute} ) {
77 push( @register, $action->name ); # Register sub name against root
80 if ( $attrs->{Local} || $attrs->{Relative} ) {
81 push( @register, join( '/', $action->namespace, $action->name ) );
83 # Register sub name as a relative path
86 $self->register_path( $c, $_, $action ) for @register;
87 return 1 if @register;
91 =head2 $self->register_path($c, $path, $action)
96 my ( $self, $c, $path, $action ) = @_;
98 $path = '/' unless length $path;
99 $path = URI->new($path)->canonical;
100 $self->{paths}{$path} = $action;
106 Sebastian Riedel, C<sri@cpan.org>
110 This program is free software, you can redistribute it and/or modify it under
111 the same terms as Perl itself.