1 package Catalyst::DispatchType::Path;
4 extends 'Catalyst::DispatchType';
14 default => sub { +{} },
21 Catalyst::DispatchType::Path - Path DispatchType
31 =head2 $self->list($c)
33 Debug output for Path dispatch points
38 my ( $self, $c ) = @_;
39 my $column_width = Catalyst::Utils::term_width() - 35 - 9;
40 my $paths = Text::SimpleTable->new(
41 [ 35, 'Path' ], [ $column_width, 'Private' ]
43 foreach my $path ( sort keys %{ $self->_paths } ) {
44 my $display_path = $path eq '/' ? $path : "/$path";
45 foreach my $action ( @{ $self->_paths->{$path} } ) {
46 $paths->row( $display_path, "/$action" );
49 $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" )
50 if ( keys %{ $self->_paths } );
53 =head2 $self->match( $c, $path )
55 For each action registered to this exact path, offers the action a chance to
56 match the path (in the order in which they were registered). Succeeds on the
57 first action that matches, if any; if not, returns 0.
62 my ( $self, $c, $path ) = @_;
64 $path = '/' if !defined $path || !length $path;
66 foreach my $action ( @{ $self->_paths->{$path} || [] } ) {
67 next unless $action->match($c);
68 $c->req->action($path);
69 $c->req->match($path);
71 $c->namespace( $action->namespace );
78 =head2 $self->register( $c, $action )
80 Calls register_path for every Path attribute for the given $action.
85 my ( $self, $c, $action ) = @_;
87 my @register = @{ $action->attributes->{Path} || [] };
89 $self->register_path( $c, $_, $action ) for @register;
91 return 1 if @register;
95 =head2 $self->register_path($c, $path, $action)
97 Registers an action at a given path.
102 my ( $self, $c, $path, $action ) = @_;
104 $path = '/' unless length $path;
105 $path = URI->new($path)->canonical;
107 unshift( @{ $self->_paths->{$path} ||= [] }, $action);
112 =head2 $self->uri_for_action($action, $captures)
114 get a URI part for an action; always returns undef is $captures is set
115 since Path actions don't have captures
120 my ( $self, $action, $captures ) = @_;
122 return undef if @$captures;
124 if (my $paths = $action->attributes->{Path}) {
125 my $path = $paths->[0];
126 $path = '/' unless length($path);
127 $path = "/${path}" unless ($path =~ m/^\//);
128 $path = URI->new($path)->canonical;
137 Catalyst Contributors, see Catalyst.pm
141 This program is free software, you can redistribute it and/or modify it under
142 the same terms as Perl itself.
146 __PACKAGE__->meta->make_immutable;