1 package Catalyst::DispatchType::Path;
4 extends 'Catalyst::DispatchType';
7 #use base qw/Catalyst::DispatchType/;
13 Catalyst::DispatchType::Path - Path DispatchType
23 =head2 $self->list($c)
25 Debug output for Path dispatch points
30 my ( $self, $c ) = @_;
31 my $paths = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] );
32 foreach my $path ( sort keys %{ $self->{paths} } ) {
33 my $display_path = $path eq '/' ? $path : "/$path";
34 foreach my $action ( @{ $self->{paths}->{$path} } ) {
35 $paths->row( $display_path, "/$action" );
38 $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" )
39 if ( keys %{ $self->{paths} } );
42 =head2 $self->match( $c, $path )
44 For each action registered to this exact path, offers the action a chance to
45 match the path (in the order in which they were registered). Succeeds on the
46 first action that matches, if any; if not, returns 0.
51 my ( $self, $c, $path ) = @_;
55 foreach my $action ( @{ $self->{paths}->{$path} || [] } ) {
56 next unless $action->match($c);
57 $c->req->action($path);
58 $c->req->match($path);
60 $c->namespace( $action->namespace );
67 =head2 $self->register( $c, $action )
69 Calls register_path for every Path attribute for the given $action.
74 my ( $self, $c, $action ) = @_;
76 my @register = @{ $action->attributes->{Path} || [] };
78 $self->register_path( $c, $_, $action ) for @register;
80 return 1 if @register;
84 =head2 $self->register_path($c, $path, $action)
86 Registers an action at a given path.
91 my ( $self, $c, $path, $action ) = @_;
93 $path = '/' unless length $path;
94 $path = URI->new($path)->canonical;
96 unshift( @{ $self->{paths}{$path} ||= [] }, $action);
101 =head2 $self->uri_for_action($action, $captures)
103 get a URI part for an action; always returns undef is $captures is set
104 since Path actions don't have captures
109 my ( $self, $action, $captures ) = @_;
111 return undef if @$captures;
113 if (my $paths = $action->attributes->{Path}) {
114 my $path = $paths->[0];
115 $path = '/' unless length($path);
116 $path = "/${path}" unless ($path =~ m/^\//);
117 $path = URI->new($path)->canonical;
127 Sebastian Riedel, C<sri@cpan.org>
131 This program is free software, you can redistribute it and/or modify it under
132 the same terms as Perl itself.