1 package Catalyst::DispatchType::Path;
4 use base qw/Catalyst::DispatchType/;
10 Catalyst::DispatchType::Path - Path DispatchType
20 =head2 $self->list($c)
22 Debug output for Path dispatch points
27 my ( $self, $c ) = @_;
28 my $paths = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] );
29 foreach my $path ( sort keys %{ $self->{paths} } ) {
30 foreach my $action ( @{ $self->{paths}->{$path} } ) {
31 $path = "/$path" unless $path eq '/';
32 $paths->row( "$path", "/$action" );
35 $c->log->debug( "Loaded Path actions:\n" . $paths->draw )
36 if ( keys %{ $self->{paths} } );
39 =head2 $self->match( $c, $path )
41 Check for paths that match the given path.
46 my ( $self, $c, $path ) = @_;
50 foreach my $action ( @{ $self->{paths}->{$path} || [] } ) {
51 next unless $action->match($c);
52 $c->req->action($path);
53 $c->req->match($path);
55 $c->namespace( $action->namespace );
62 =head2 $self->register( $c, $action )
64 Call register_path for every path attribute in the given $action.
69 my ( $self, $c, $action ) = @_;
71 my @register = @{ $action->attributes->{Path} || [] };
73 $self->register_path( $c, $_, $action ) for @register;
75 return 1 if @register;
79 =head2 $self->register_path($c, $path, $action)
81 register an action at a given path.
86 my ( $self, $c, $path, $action ) = @_;
88 $path = '/' unless length $path;
89 $path = URI->new($path)->canonical;
91 unshift( @{ $self->{paths}{$path} ||= [] }, $action);
96 =head2 $self->uri_for_action($action, $captures)
98 get a URI part for an action; always returns undef is $captures is set
99 since Path actions don't have captures
104 my ( $self, $action, $captures ) = @_;
106 return undef if @$captures;
108 if (my $paths = $action->attributes->{Path}) {
109 my $path = $paths->[0];
110 $path = '/' unless length($path);
111 $path = "/${path}" unless ($path =~ m/^\//);
112 $path = URI->new($path)->canonical;
122 Sebastian Riedel, C<sri@cpan.org>
126 This program is free software, you can redistribute it and/or modify it under
127 the same terms as Perl itself.