1 package Catalyst::DispatchType::Path;
6 extends 'Catalyst::DispatchType';
15 default => sub { +{} },
22 Catalyst::DispatchType::Path - Path DispatchType
32 =head2 $self->list($c)
34 Debug output for Path dispatch points
39 my ( $self, $c ) = @_;
40 my $paths = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] );
41 foreach my $path ( sort keys %{ $self->_paths } ) {
42 my $display_path = $path eq '/' ? $path : "/$path";
43 foreach my $action ( @{ $self->_paths->{$path} } ) {
44 $paths->row( $display_path, "/$action" );
47 $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" )
48 if ( keys %{ $self->_paths } );
51 =head2 $self->match( $c, $path )
53 For each action registered to this exact path, offers the action a chance to
54 match the path (in the order in which they were registered). Succeeds on the
55 first action that matches, if any; if not, returns 0.
60 my ( $self, $c, $path ) = @_;
64 foreach my $action ( @{ $self->_paths->{$path} || [] } ) {
65 next unless $action->match($c);
66 $c->req->action($path);
67 $c->req->match($path);
69 $c->namespace( $action->namespace );
76 =head2 $self->register( $c, $action )
78 Calls register_path for every Path attribute for the given $action.
83 my ( $self, $c, $action ) = @_;
85 my @register = @{ $action->attributes->{Path} || [] };
87 $self->register_path( $c, $_, $action ) for @register;
89 return 1 if @register;
93 =head2 $self->register_path($c, $path, $action)
95 Registers an action at a given path.
100 my ( $self, $c, $path, $action ) = @_;
102 $path = '/' unless length $path;
103 $path = URI->new($path)->canonical;
105 unshift( @{ $self->_paths->{$path} ||= [] }, $action);
110 =head2 $self->uri_for_action($action, $captures)
112 get a URI part for an action; always returns undef is $captures is set
113 since Path actions don't have captures
118 my ( $self, $action, $captures ) = @_;
120 return undef if @$captures;
122 if (my $paths = $action->attributes->{Path}) {
123 my $path = $paths->[0];
124 $path = '/' unless length($path);
125 $path = "/${path}" unless ($path =~ m/^\//);
126 $path = URI->new($path)->canonical;
136 Sebastian Riedel, C<sri@cpan.org>
140 This program is free software, you can redistribute it and/or modify it under
141 the same terms as Perl itself.
145 __PACKAGE__->meta->make_immutable;