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 my $display_path = $path eq '/' ? $path : "/$path";
31 foreach my $action ( @{ $self->{paths}->{$path} } ) {
32 $paths->row( $display_path, "/$action" );
35 $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" )
36 if ( keys %{ $self->{paths} } );
39 =head2 $self->match( $c, $path )
41 For each action registered to this exact path, offers the action a chance to
42 match the path (in the order in which they were registered). Succeeds on the
43 first action that matches, if any; if not, returns 0.
48 my ( $self, $c, $path ) = @_;
52 foreach my $action ( @{ $self->{paths}->{$path} || [] } ) {
53 next unless $action->match($c);
54 $c->req->action($path);
55 $c->req->match($path);
57 $c->namespace( $action->namespace );
64 =head2 $self->register( $c, $action )
66 Calls register_path for every Path attribute for the given $action.
71 my ( $self, $c, $action ) = @_;
73 my @register = @{ $action->attributes->{Path} || [] };
75 $self->register_path( $c, $_, $action ) for @register;
77 return 1 if @register;
81 =head2 $self->register_path($c, $path, $action)
83 Registers an action at a given path.
88 my ( $self, $c, $path, $action ) = @_;
90 $path = '/' unless length $path;
91 $path = URI->new($path)->canonical;
93 unshift( @{ $self->{paths}{$path} ||= [] }, $action);
98 =head2 $self->uri_for_action($action, $captures)
100 get a URI part for an action; always returns undef is $captures is set
101 since Path actions don't have captures
106 my ( $self, $action, $captures ) = @_;
108 return undef if @$captures;
110 if (my $paths = $action->attributes->{Path}) {
111 my $path = $paths->[0];
112 $path = '/' unless length($path);
113 $path = "/${path}" unless ($path =~ m/^\//);
114 $path = URI->new($path)->canonical;
124 Sebastian Riedel, C<sri@cpan.org>
128 This program is free software, you can redistribute it and/or modify it under
129 the same terms as Perl itself.