1 package Catalyst::DispatchType::Path;
4 use base qw/Catalyst::DispatchType/;
11 Catalyst::DispatchType::Path - Path DispatchType
21 =head2 $self->list($c)
23 Debug output for Path dispatch points
28 my ( $self, $c ) = @_;
29 my $column_width = Catalyst::Utils::term_width() - 35 - 9;
30 my $paths = Text::SimpleTable->new(
31 [ 35, 'Path' ], [ $column_width, 'Private' ]
33 foreach my $path ( sort keys %{ $self->{paths} } ) {
34 my $display_path = $path eq '/' ? $path : "/$path";
35 foreach my $action ( @{ $self->{paths}->{$path} } ) {
36 $paths->row( $display_path, "/$action" );
39 $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" )
40 if ( keys %{ $self->{paths} } );
43 =head2 $self->match( $c, $path )
45 For each action registered to this exact path, offers the action a chance to
46 match the path (in the order in which they were registered). Succeeds on the
47 first action that matches, if any; if not, returns 0.
52 my ( $self, $c, $path ) = @_;
54 $path = '/' if !defined $path || !length $path;
56 foreach my $action ( @{ $self->{paths}->{$path} || [] } ) {
57 next unless $action->match($c);
58 $c->req->action($path);
59 $c->req->match($path);
61 $c->namespace( $action->namespace );
68 =head2 $self->register( $c, $action )
70 Calls register_path for every Path attribute for the given $action.
75 my ( $self, $c, $action ) = @_;
77 my @register = @{ $action->attributes->{Path} || [] };
79 $self->register_path( $c, $_, $action ) for @register;
81 return 1 if @register;
85 =head2 $self->register_path($c, $path, $action)
87 Registers an action at a given path.
92 my ( $self, $c, $path, $action ) = @_;
94 $path = '/' unless length $path;
95 $path = URI->new($path)->canonical;
97 unshift( @{ $self->{paths}{$path} ||= [] }, $action);
102 =head2 $self->uri_for_action($action, $captures)
104 get a URI part for an action; always returns undef is $captures is set
105 since Path actions don't have captures
110 my ( $self, $action, $captures ) = @_;
112 return undef if @$captures;
114 if (my $paths = $action->attributes->{Path}) {
115 my $path = $paths->[0];
116 $path = '/' unless length($path);
117 $path = "/${path}" unless ($path =~ m/^\//);
118 $path = URI->new($path)->canonical;
127 Catalyst Contributors, see Catalyst.pm
131 This program is free software, you can redistribute it and/or modify it under
132 the same terms as Perl itself.