1 package Catalyst::DispatchType::Path;
4 extends 'Catalyst::DispatchType';
14 default => sub { +{} },
21 Catalyst::DispatchType::Path - Path DispatchType
25 See L<Catalyst::DispatchType>.
29 Dispatch type managing full path matching behaviour. For more information on
34 =item * L<Catalyst::Manual::Intro> for how they affect application authors
36 =item * L<Catalyst::DispatchType> for implementation information.
42 =head2 $self->list($c)
44 Debug output for Path dispatch points
49 my ( $self, $c ) = @_;
50 my $column_width = Catalyst::Utils::term_width() - 35 - 9;
51 my $paths = Text::SimpleTable->new(
52 [ 35, 'Path' ], [ $column_width, 'Private' ]
54 foreach my $path ( sort keys %{ $self->_paths } ) {
55 my $display_path = $path eq '/' ? $path : "/$path";
56 foreach my $action ( @{ $self->_paths->{$path} } ) {
57 $paths->row( $display_path, "/$action" );
60 $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" )
61 if ( keys %{ $self->_paths } );
64 =head2 $self->match( $c, $path )
66 For each action registered to this exact path, offers the action a chance to
67 match the path (in the order in which they were registered). Succeeds on the
68 first action that matches, if any; if not, returns 0.
73 my ( $self, $c, $path ) = @_;
75 $path = '/' if !defined $path || !length $path;
77 my @actions = @{ $self->_paths->{$path} || [] };
79 foreach my $action ( @actions ) {
80 next unless $action->match($c);
81 $c->req->action($path);
82 $c->req->match($path);
84 $c->namespace( $action->namespace );
91 =head2 $self->register( $c, $action )
93 Calls register_path for every Path attribute for the given $action.
98 my ( $self, $c, $action ) = @_;
100 my @register = @{ $action->attributes->{Path} || [] };
102 $self->register_path( $c, $_, $action ) for @register;
104 return 1 if @register;
108 =head2 $self->register_path($c, $path, $action)
110 Registers an action at a given path.
115 my ( $self, $c, $path, $action ) = @_;
117 $path = '/' unless length $path;
118 $path = URI->new($path)->canonical;
119 $path =~ s{(?<=[^/])/+\z}{};
121 $self->_paths->{$path} = [
122 sort { $a <=> $b } ($action, @{ $self->_paths->{$path} || [] })
128 =head2 $self->uri_for_action($action, $captures)
130 get a URI part for an action; always returns undef is $captures is set
131 since Path actions don't have captures
136 my ( $self, $action, $captures ) = @_;
138 return undef if @$captures;
140 if (my $paths = $action->attributes->{Path}) {
141 my $path = $paths->[0];
142 $path = '/' unless length($path);
143 $path = "/${path}" unless ($path =~ m/^\//);
144 $path = URI->new($path)->canonical;
153 Catalyst Contributors, see Catalyst.pm
157 This library is free software. You can redistribute it and/or modify it under
158 the same terms as Perl itself.
162 __PACKAGE__->meta->make_immutable;