Catalyst-Plugin-URI

 view release on metacpan or  search on metacpan

README.mkdn  view on Meta::CPAN

    sub name_action :Local Args(0) Name(hi) {
      my ($self, $c) = @_;
      # rest of action
    }

    my $url = $c->uri("#hi");

This allows you to specify the action by its name from any controller.  We don't
allow you to use the same name twice, and we also throw an exception if you attempt
to add a name to an intermediate action in a chain of actions (you can only name
an endpoint).

Lastly For ease of use if the first argument is an action object we just pass it
down to 'uri\_for'.  That way you should be able to use this method for all types
of URL creation.

# OTHER SIMILAR OPTIONS

[Catalyst](https://metacpan.org/pod/Catalyst) offers a second way to make URLs that use the action private
name, the 'uri\_for\_action' method.  However this suffers from a bug where
'path/action' and '/path/action' work the same (no support for relative

lib/Catalyst/Plugin/URI.pm  view on Meta::CPAN


  if($version == 1) {
    Moo::_Utils::_install_tracked($c, 'uri', $uri_v1);
  } elsif($version == 2) {
    Moo::_Utils::_install_tracked($c, 'uri', $uri_v2);
    
    # V2 does its own version of named actions
    my %action_hash = %{$c->dispatcher->_action_hash||+{}};
    foreach my $key (keys %action_hash) {
      if(my ($name) = @{$action_hash{$key}->attributes->{Name}||[]}) {
        croak "You can only name endpoint actions on a chain"
          if defined$action_hash{$key}->attributes->{CaptureArgs};
        croak "Named action '$name' is already defined"
          if $c->dispatcher->_action_hash->{"/#$name"};
        $c->dispatcher->_action_hash->{"/#$name"} = $action_hash{$key};      
      }
    }
    foreach my $method(qw/detach forward visit go/) {
      Moo::_Utils::_install_modifier($c, 'around', $method, sub { 
        my ($orig, $c, $action_proto, @args) = @_;
        my $action;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.529 second using v1.00-cache-2.02-grep-82fe00e-cpan-4673cadbf75 )