With tests, missing docs.
# strip CaptureArgs into list
push(@captures, splice(@parts, 0, $capture_attr->[0]));
+ # check if the action may fit, depending on a given test by the app
+ if ($action->can('match_captures')) { next TRY_ACTION unless $action->match_captures($c, \@captures) }
+
# try the remaining parts against children of this action
my ($actions, $captures, $action_parts, $n_pathparts) = $self->recurse_match(
$c, '/'.$action->reverse, \@parts
ok( index($content, $path) > 1, 'uri can round trip through uri_for' )
or diag("Expected $path, got $content");
}
+
+ #
+ # match_captures
+ #
+ {
+
+ ok( my $response = request('http://localhost/chained/match_captures/foo/bar'), 'match_captures: falling through' );
+ is($response->header('X-TestAppActionTestMatchCaptures'), 'fallthrough', 'match_captures: fell through');
+
+ ok($response = request('http://localhost/chained/match_captures/force/bar'), 'match_captures: *not* falling through' );
+ is($response->header('X-TestAppActionTestMatchCaptures'), 'forcing', 'match_captures: forced');
+ is($response->header('X-TestAppActionTestMatchCapturesHasRan'), 'yes', 'match_captures: actually ran');
+ }
}
done_testing;
--- /dev/null
+package TestApp::ActionRole::TestMatchCaptures;
+
+use Moose::Role;
+use namespace::autoclean;
+
+sub match_captures {
+ my ($self, $c, $cap) = @_;
+ if ($cap->[0] eq 'force') {
+ $c->res->header( 'X-TestAppActionTestMatchCaptures', 'forcing' );
+ return 1;
+ } else {
+ $c->res->header( 'X-TestAppActionTestMatchCaptures', 'fallthrough' );
+ return 0;
+ }
+}
+
+1;
\ No newline at end of file
use HTML::Entities;
-use base qw/Catalyst::Controller/;
+use base qw/Catalyst::Controller::ActionRole/;
sub begin :Private { }
$c->stash->{no_end} = 1;
}
+sub match_captures : Chained('/') PathPart('chained/match_captures') CaptureArgs(1) Does('~TestMatchCaptures') {
+ my ($self, $c) = @_;
+ $c->res->header( 'X-TestAppActionTestMatchCapturesHasRan', 'yes');
+}
+
+sub match_captures_end : Chained('match_captures') PathPart('bar') Args(0) { }
+
sub end :Private {
my ($self, $c) = @_;
return if $c->stash->{no_end};