1 package Catalyst::DispatchType::Path;
5 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 $paths = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] );
40 foreach my $path ( sort keys %{ $self->_paths } ) {
41 my $display_path = $path eq '/' ? $path : "/$path";
42 foreach my $action ( @{ $self->_paths->{$path} } ) {
43 $paths->row( $display_path, "/$action" );
46 $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" )
47 if ( keys %{ $self->_paths } );
50 =head2 $self->match( $c, $path )
52 For each action registered to this exact path, offers the action a chance to
53 match the path (in the order in which they were registered). Succeeds on the
54 first action that matches, if any; if not, returns 0.
59 my ( $self, $c, $path ) = @_;
63 foreach my $action ( @{ $self->_paths->{$path} || [] } ) {
64 next unless $action->match($c);
65 $c->req->action($path);
66 $c->req->match($path);
68 $c->namespace( $action->namespace );
75 =head2 $self->register( $c, $action )
77 Calls register_path for every Path attribute for the given $action.
82 my ( $self, $c, $action ) = @_;
84 my @register = @{ $action->attributes->{Path} || [] };
86 $self->register_path( $c, $_, $action ) for @register;
88 return 1 if @register;
92 =head2 $self->register_path($c, $path, $action)
94 Registers an action at a given path.
99 my ( $self, $c, $path, $action ) = @_;
101 $path = '/' unless length $path;
102 $path = URI->new($path)->canonical;
104 unshift( @{ $self->_paths->{$path} ||= [] }, $action);
109 =head2 $self->uri_for_action($action, $captures)
111 get a URI part for an action; always returns undef is $captures is set
112 since Path actions don't have captures
117 my ( $self, $action, $captures ) = @_;
119 return undef if @$captures;
121 if (my $paths = $action->attributes->{Path}) {
122 my $path = $paths->[0];
123 $path = '/' unless length($path);
124 $path = "/${path}" unless ($path =~ m/^\//);
125 $path = URI->new($path)->canonical;
135 Sebastian Riedel, C<sri@cpan.org>
139 This program is free software, you can redistribute it and/or modify it under
140 the same terms as Perl itself.
144 __PACKAGE__->meta->make_immutable;