1 package Catalyst::DispatchType::Path;
4 extends 'Catalyst::DispatchType';
14 default => sub { +{} },
21 Catalyst::DispatchType::Path - Path DispatchType
25 See L<Catalyst::DispatchType>.
29 Dispatch type managing full path matching behaviour. For more information on
34 =item * L<Catalyst::Manual::Intro> for how they affect application authors
36 =item * L<Catalyst::DispatchType> for implementation information.
42 =head2 $self->list($c)
44 Debug output for Path dispatch points
49 my ( $self, $c ) = @_;
50 my $avail_width = Catalyst::Utils::term_width() - 9;
51 my $col1_width = ($avail_width * .50) < 35 ? 35 : int($avail_width * .50);
52 my $col2_width = $avail_width - $col1_width;
53 my $paths = Text::SimpleTable->new(
54 [ $col1_width, 'Path' ], [ $col2_width, 'Private' ]
56 foreach my $path ( sort keys %{ $self->_paths } ) {
57 my $display_path = $path eq '/' ? $path : "/$path";
58 foreach my $action ( @{ $self->_paths->{$path} } ) {
59 $paths->row( $display_path, "/$action" );
62 $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" )
63 if ( keys %{ $self->_paths } );
66 =head2 $self->match( $c, $path )
68 For each action registered to this exact path, offers the action a chance to
69 match the path (in the order in which they were registered). Succeeds on the
70 first action that matches, if any; if not, returns 0.
75 my ( $self, $c, $path ) = @_;
77 $path = '/' if !defined $path || !length $path;
79 my @actions = @{ $self->_paths->{$path} || [] };
81 foreach my $action ( @actions ) {
82 next unless $action->match($c);
83 $c->req->action($path);
84 $c->req->match($path);
86 $c->namespace( $action->namespace );
93 =head2 $self->register( $c, $action )
95 Calls register_path for every Path attribute for the given $action.
100 my ( $self, $c, $action ) = @_;
102 my @register = @{ $action->attributes->{Path} || [] };
104 $self->register_path( $c, $_, $action ) for @register;
106 return 1 if @register;
110 =head2 $self->register_path($c, $path, $action)
112 Registers an action at a given path.
117 my ( $self, $c, $path, $action ) = @_;
119 $path = '/' unless length $path;
120 $path = URI->new($path)->canonical;
121 $path =~ s{(?<=[^/])/+\z}{};
123 $self->_paths->{$path} = [
124 sort { $a->compare($b) } ($action, @{ $self->_paths->{$path} || [] })
130 =head2 $self->uri_for_action($action, $captures)
132 get a URI part for an action; always returns undef is $captures is set
133 since Path actions don't have captures
138 my ( $self, $action, $captures ) = @_;
140 return undef if @$captures;
142 if (my $paths = $action->attributes->{Path}) {
143 my $path = $paths->[0];
144 $path = '/' unless length($path);
145 $path = "/${path}" unless ($path =~ m/^\//);
146 $path = URI->new($path)->canonical;
155 Catalyst Contributors, see Catalyst.pm
159 This library is free software. You can redistribute it and/or modify it under
160 the same terms as Perl itself.
164 __PACKAGE__->meta->make_immutable;