1 package Catalyst::DispatchType::Path;
4 extends 'Catalyst::DispatchType';
7 #use base qw/Catalyst::DispatchType/;
15 default => sub { +{} },
20 Catalyst::DispatchType::Path - Path DispatchType
30 =head2 $self->list($c)
32 Debug output for Path dispatch points
37 my ( $self, $c ) = @_;
38 my $paths = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] );
39 foreach my $path ( sort keys %{ $self->_paths } ) {
40 my $display_path = $path eq '/' ? $path : "/$path";
41 foreach my $action ( @{ $self->_paths->{$path} } ) {
42 $paths->row( $display_path, "/$action" );
45 $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" )
46 if ( keys %{ $self->_paths } );
49 =head2 $self->match( $c, $path )
51 For each action registered to this exact path, offers the action a chance to
52 match the path (in the order in which they were registered). Succeeds on the
53 first action that matches, if any; if not, returns 0.
58 my ( $self, $c, $path ) = @_;
62 foreach my $action ( @{ $self->_paths->{$path} || [] } ) {
63 next unless $action->match($c);
64 $c->req->action($path);
65 $c->req->match($path);
67 $c->namespace( $action->namespace );
74 =head2 $self->register( $c, $action )
76 Calls register_path for every Path attribute for the given $action.
81 my ( $self, $c, $action ) = @_;
83 my @register = @{ $action->attributes->{Path} || [] };
85 $self->register_path( $c, $_, $action ) for @register;
87 return 1 if @register;
91 =head2 $self->register_path($c, $path, $action)
93 Registers an action at a given path.
98 my ( $self, $c, $path, $action ) = @_;
100 $path = '/' unless length $path;
101 $path = URI->new($path)->canonical;
103 unshift( @{ $self->_paths->{$path} ||= [] }, $action);
108 =head2 $self->uri_for_action($action, $captures)
110 get a URI part for an action; always returns undef is $captures is set
111 since Path actions don't have captures
116 my ( $self, $action, $captures ) = @_;
118 return undef if @$captures;
120 if (my $paths = $action->attributes->{Path}) {
121 my $path = $paths->[0];
122 $path = '/' unless length($path);
123 $path = "/${path}" unless ($path =~ m/^\//);
124 $path = URI->new($path)->canonical;
134 Sebastian Riedel, C<sri@cpan.org>
138 This program is free software, you can redistribute it and/or modify it under
139 the same terms as Perl itself.
144 __PACKAGE__->meta->make_immutable;