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 foreach my $action ( @{ $self->_paths->{$path} || [] } ) {
78 next unless $action->match($c);
79 $c->req->action($path);
80 $c->req->match($path);
82 $c->namespace( $action->namespace );
89 =head2 $self->register( $c, $action )
91 Calls register_path for every Path attribute for the given $action.
96 my ( $self, $c, $action ) = @_;
98 my @register = @{ $action->attributes->{Path} || [] };
100 $self->register_path( $c, $_, $action ) for @register;
102 return 1 if @register;
106 =head2 $self->register_path($c, $path, $action)
108 Registers an action at a given path.
113 my ( $self, $c, $path, $action ) = @_;
115 $path = '/' unless length $path;
116 $path = URI->new($path)->canonical;
118 unshift( @{ $self->_paths->{$path} ||= [] }, $action);
123 =head2 $self->uri_for_action($action, $captures)
125 get a URI part for an action; always returns undef is $captures is set
126 since Path actions don't have captures
131 my ( $self, $action, $captures ) = @_;
133 return undef if @$captures;
135 if (my $paths = $action->attributes->{Path}) {
136 my $path = $paths->[0];
137 $path = '/' unless length($path);
138 $path = "/${path}" unless ($path =~ m/^\//);
139 $path = URI->new($path)->canonical;
148 Catalyst Contributors, see Catalyst.pm
152 This program is free software, you can redistribute it and/or modify it under
153 the same terms as Perl itself.
157 __PACKAGE__->meta->make_immutable;