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 # sort from least args to most
78 my @actions = sort { ($b->attributes->{Args}||0) <=>
79 ($a->attributes->{Args}||0) }
80 @{ $self->_paths->{$path} || [] };
82 foreach my $action ( @actions ) {
83 next unless $action->match($c);
84 $c->req->action($path);
85 $c->req->match($path);
87 $c->namespace( $action->namespace );
94 =head2 $self->register( $c, $action )
96 Calls register_path for every Path attribute for the given $action.
101 my ( $self, $c, $action ) = @_;
103 my @register = @{ $action->attributes->{Path} || [] };
105 $self->register_path( $c, $_, $action ) for @register;
107 return 1 if @register;
111 =head2 $self->register_path($c, $path, $action)
113 Registers an action at a given path.
118 my ( $self, $c, $path, $action ) = @_;
120 $path = '/' unless length $path;
121 $path = URI->new($path)->canonical;
123 unshift( @{ $self->_paths->{$path} ||= [] }, $action);
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 program is free software, you can redistribute it and/or modify it under
158 the same terms as Perl itself.
162 __PACKAGE__->meta->make_immutable;