From: John Napiorkowski Date: Thu, 26 Mar 2015 16:48:02 +0000 (-0500) Subject: fixed POD error X-Git-Tag: 5.90089_002~22 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=c1192f1ed63f124eb2d143e10b215703e7dc6284 fixed POD error --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 03acccc..f013027 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1498,13 +1498,28 @@ sub uri_for { unshift @encoded_args, splice @$captures, $num_captures; } - $path = $c->dispatcher->uri_for_action($action, $captures); + # use Devel::Dwarn;Dwarn $captures; + + if($action->has_captures_constraints) { + unless($action->match_captures($c, $captures)) { + carp "@{$captures} do not match the type constraints in $action"; + } + } + + $path = $c->dispatcher->uri_for_action($action, $captures); if (not defined $path) { $c->log->debug(qq/Can't find uri_for action '$action' @$captures/) if $c->debug; return undef; } $path = '/' if $path eq ''; + + # At this point @encoded_args is the remaining Args (all captures removed). + if($action->has_args_constraints) { + unless($action->match_args($c,\@encoded_args)) { + carp "@encoded_args do not match the type constraints in $action"; + } + } } unshift(@encoded_args, $path); @@ -1567,6 +1582,9 @@ sub uri_for { } @keys); } + warn $base; + warn $args; + my $res = bless(\"${base}${args}${query}", $class); $res; } diff --git a/lib/Catalyst/Action.pm b/lib/Catalyst/Action.pm index 8c86df0..ec30c7a 100644 --- a/lib/Catalyst/Action.pm +++ b/lib/Catalyst/Action.pm @@ -271,6 +271,12 @@ sub execute { sub match { my ( $self, $c ) = @_; + return $self->match_args($c, $c->req->args); +} + +sub match_args { + my ($self, $c, $args) = @_; + my @args = @{$args||[]}; # If infinite args, we always match return 1 if $self->normalized_arg_number == ~0; @@ -287,7 +293,7 @@ sub match { $self->args_constraints->[0]->is_a_type_of('ClassName') ) ) { - return $self->args_constraints->[0]->check($c->req->args); + return $self->args_constraints->[0]->check($args); # Removing coercion stuff for the first go #if($self->args_constraints->[0]->coercion && $self->attributes->{Coerce}) { # my $coerced = $self->args_constraints->[0]->coerce($c) || return 0; @@ -297,16 +303,16 @@ sub match { } else { # Because of the way chaining works, we can expect args that are totally not # what you'd expect length wise. When they don't match length, thats a fail - return 0 unless scalar( @{ $c->req->args } ) == $self->normalized_arg_number; + return 0 unless scalar( @args ) == $self->normalized_arg_number; - for my $i(0..$#{ $c->req->args }) { - $self->args_constraints->[$i]->check($c->req->args->[$i]) || return 0; + for my $i(0..$#args) { + $self->args_constraints->[$i]->check($args[$i]) || return 0; } return 1; } } else { # Otherwise, we just need to match the number of args. - return scalar( @{ $c->req->args } ) == $self->normalized_arg_number; + return scalar( @args ) == $self->normalized_arg_number; } } @@ -400,6 +406,11 @@ of the captures for this action. Returning true from this method causes the chain match to continue, returning makes the chain not match (and alternate, less preferred chains will be attempted). +=head2 match_args($c, $args) + +Underlying feature that does the 'match' work, but doesn't require a context to +work (like 'match' does.). + =head2 resolve_type_constraint Trys to find a type constraint if you have on on a type constrained method. diff --git a/lib/Catalyst/Delta.pod b/lib/Catalyst/Delta.pod index f480a87..bbc1a36 100755 --- a/lib/Catalyst/Delta.pod +++ b/lib/Catalyst/Delta.pod @@ -12,7 +12,7 @@ Catalyst releases. =head2 Type constraints on Args and CaptureArgs. You may now use a type constraint (using L, L or preferably -L in your Args or CaptureArgs action attributes. This can be used to restrict the value of the Arg. For example: sub myaction :Local Args(Int) { ... } diff --git a/t/arg_constraints.t b/t/arg_constraints.t index fada01b..80b53f6 100644 --- a/t/arg_constraints.t +++ b/t/arg_constraints.t @@ -372,6 +372,13 @@ SKIP: { ok my $url2 = $c->uri_for($c->controller('Root')->action_for('finally'), [1,2,3,4,5,6]); warn $url2; + + ok my $url3 = $c->uri_for($c->controller('Root')->action_for('user'), 2); + warn $url3; + + ok my $url4 = $c->uri_for($c->controller('Root')->action_for('user'), [2]); + warn $url4; + } done_testing;