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 return 0 unless $action->match($c);
46 $c->req->action($path);
47 $c->req->match($path);
49 $c->namespace( $action->namespace );
56 =head2 $self->register( $c, $action )
61 my ( $self, $c, $action ) = @_;
63 my $attrs = $action->attributes;
66 foreach my $r ( @{ $attrs->{Path} || [] } ) {
68 $r = $action->namespace;
69 $r = '/' unless length $r;
71 elsif ( $r !~ m!^/! ) { # It's a relative path
72 $r = $action->namespace . "/$r";
74 push( @register, $r );
77 if ( $attrs->{Global} || $attrs->{Absolute} ) {
78 push( @register, $action->name ); # Register sub name against root
81 if ( $attrs->{Local} || $attrs->{Relative} ) {
82 push( @register, join( '/', $action->namespace, $action->name ) );
84 # Register sub name as a relative path
87 $self->register_path( $c, $_, $action ) for @register;
88 return 1 if @register;
92 =head2 $self->register_path($c, $path, $action)
97 my ( $self, $c, $path, $action ) = @_;
99 $path = '/' unless length $path;
100 $path = URI->new($path)->canonical;
101 $self->{paths}{$path} = $action;
107 Sebastian Riedel, C<sri@cpan.org>
111 This program is free software, you can redistribute it and/or modify it under
112 the same terms as Perl itself.