3 role CatalystX::Declare::Action::CatchValidationError {
5 use MooseX::Types::Moose qw( ArrayRef Str HashRef );
6 use aliased 'Moose::Meta::TypeConstraint';
8 has method_type_constraint => (
10 isa => TypeConstraint,
12 _check_action_arguments => 'check',
16 has method_named_params => (
21 has method_named_type_constraint => (
23 isa => HashRef[TypeConstraint],
26 has controller_instance => (
28 isa => 'Catalyst::Controller',
32 method extract_named_params (Object $ctx) {
35 my $tcs = $self->method_named_type_constraint;
37 if (my $named = $self->method_named_params) {
39 for my $key (@$named) {
41 next unless exists $ctx->request->params->{ $key };
43 my $value = $ctx->request->params->{ $key };
44 my $tc = $tcs->{ $key };
46 if ($tc and $tc->is_subtype_of(ArrayRef)) {
49 unless exists $ctx->request->params->{ $key };
52 unless is_ArrayRef $value;
55 $extracted{ $key } = $value;
62 around execute (Object $ctrl, Object $ctx, @rest) {
64 return $self->$orig($ctrl, $ctx, @rest, %{ $self->extract_named_params($ctx) });
67 around match (Object $ctx) {
70 unless $self->$orig($ctx);
72 unless $self->method_type_constraint;
74 my @args = ($self->controller_instance, $ctx, @{ $ctx->req->args });
75 my $tc = $self->method_type_constraint;
76 my $np = $self->extract_named_params($ctx);
77 my $ret = $tc->_type_constraint->check([\@args, $np]);