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);
} @keys);
}
+ warn $base;
+ warn $args;
+
my $res = bless(\"${base}${args}${query}", $class);
$res;
}
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;
$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;
} 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;
}
}
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.
=head2 Type constraints on Args and CaptureArgs.
You may now use a type constraint (using L<Moose>, L<MooseX::Types> or preferably
-L<Type::Tiny) in your Args or CaptureArgs action attributes. This can be used
+L<Type::Tiny> 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) { ... }
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;