1 package Catalyst::DispatchType::Path;
4 extends 'Catalyst::DispatchType';
15 default => sub { +{} },
22 Catalyst::DispatchType::Path - Path DispatchType
26 See L<Catalyst::DispatchType>.
30 Dispatch type managing full path matching behaviour. For more information on
35 =item * L<Catalyst::Manual::Intro> for how they affect application authors
37 =item * L<Catalyst::DispatchType> for implementation information.
43 =head2 $self->list($c)
45 Debug output for Path dispatch points
50 my ( $self, $c ) = @_;
51 my $column_width = Catalyst::Utils::term_width() - 35 - 9;
52 my $paths = Text::SimpleTable->new(
53 [ 35, 'Path' ], [ $column_width, 'Private' ]
55 foreach my $path ( sort keys %{ $self->_paths } ) {
56 my $display_path = $path eq '/' ? $path : "/$path";
57 foreach my $action ( @{ $self->_paths->{$path} } ) {
58 $paths->row( $display_path, "/$action" );
61 $c->log->debug( "Loaded Path actions:\n" . $paths->draw . "\n" )
62 if ( keys %{ $self->_paths } );
65 sub _action_args_sort_order {
66 my ( $self, $action ) = @_;
68 my ($args) = @{ $action->attributes->{Args} || [] };
70 return $args if Scalar::Util::looks_like_number($args);
75 =head2 $self->match( $c, $path )
77 For each action registered to this exact path, offers the action a chance to
78 match the path (in the order in which they were registered). Succeeds on the
79 first action that matches, if any; if not, returns 0.
84 my ( $self, $c, $path ) = @_;
86 $path = '/' if !defined $path || !length $path;
88 # sort from least args to most
89 my @actions = sort { $self->_action_args_sort_order($a) <=>
90 $self->_action_args_sort_order($b) }
91 @{ $self->_paths->{$path} || [] };
93 foreach my $action ( @actions ) {
94 next unless $action->match($c);
95 $c->req->action($path);
96 $c->req->match($path);
98 $c->namespace( $action->namespace );
105 =head2 $self->register( $c, $action )
107 Calls register_path for every Path attribute for the given $action.
112 my ( $self, $c, $action ) = @_;
114 my @register = @{ $action->attributes->{Path} || [] };
116 $self->register_path( $c, $_, $action ) for @register;
118 return 1 if @register;
122 =head2 $self->register_path($c, $path, $action)
124 Registers an action at a given path.
129 my ( $self, $c, $path, $action ) = @_;
131 $path = '/' unless length $path;
132 $path = URI->new($path)->canonical;
134 unshift( @{ $self->_paths->{$path} ||= [] }, $action);
139 =head2 $self->uri_for_action($action, $captures)
141 get a URI part for an action; always returns undef is $captures is set
142 since Path actions don't have captures
147 my ( $self, $action, $captures ) = @_;
149 return undef if @$captures;
151 if (my $paths = $action->attributes->{Path}) {
152 my $path = $paths->[0];
153 $path = '/' unless length($path);
154 $path = "/${path}" unless ($path =~ m/^\//);
155 $path = URI->new($path)->canonical;
164 Catalyst Contributors, see Catalyst.pm
168 This library is free software. You can redistribute it and/or modify it under
169 the same terms as Perl itself.
173 __PACKAGE__->meta->make_immutable;