X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=f44b9dbb7444adb2b90634d715d1e3f3b3bfdc24;hp=29a6e89cf537ea17779d2ca3dbb315e000880e3b;hb=ea0e58d9d85d93bf94c3ffa6b4d7b71b200bbdf1;hpb=2a5635138b6600a5fb2bf1b7d040d32582eddd24 diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 29a6e89..f44b9db 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -312,6 +312,7 @@ Returns the named action by its full path. sub get_action_by_path { my ( $self, $path ) = @_; + $path =~ s/^\///; $path = "/$path" unless $path =~ /\//; $self->action_hash->{$path}; } @@ -355,6 +356,27 @@ sub get_containers { my @parts = split '/', $namespace; } +=head2 $self->uri_for_action($action, \@captures) + +Takes a Catalyst::Action object and action parameters and returns a URI +part such that if $c->req->path were this URI part, this action would be +dispatched to with $c->req->captures set to the supplied arrayref. + +If the action object is not available for external dispatch or the dispatcher +cannot determine an appropriate URI, this method will return undef. + +=cut + +sub uri_for_action { + my ( $self, $action, $captures) = @_; + $captures ||= []; + foreach my $dispatch_type ( @{ $self->dispatch_types } ) { + my $uri = $dispatch_type->uri_for_action( $action, $captures ); + return $uri if defined($uri); + } + return undef; +} + =head2 $self->register( $c, $action ) Make sure all required dispatch types for this action are loaded, then