1 package Catalyst::DispatchType::Path;
7 extends 'Catalyst::DispatchType';
18 Catalyst::DispatchType::Path - Path DispatchType
28 =head2 $self->list($c)
30 Debug output for Path dispatch points
35 my ( $self, $c ) = @_;
36 my %paths = %{ $self->_paths };
37 my @keys = sort keys %paths;
39 my $paths_table = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] );
40 foreach my $path ( @keys ) {
41 my $display_path = $path eq '/' ? $path : "/$path";
42 foreach my $action ( @{ $paths{$path} } ) {
43 $paths_table->row( $display_path, "/$action" );
46 $c->log->debug( "Loaded Path actions:\n" . $paths_table->draw . "\n" );
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.