implemented action dispatching by type
[catagits/CatalystX-Declare.git] / lib / CatalystX / Declare / Action / CatchValidationError.pm
CommitLineData
5fb5cef1 1use MooseX::Declare;
2
3role CatalystX::Declare::Action::CatchValidationError {
4
5 use TryCatch;
6
ed4a2203 7 use aliased 'Moose::Meta::TypeConstraint';
8
9 has method_type_constraint => (
10 is => 'rw',
11 isa => TypeConstraint,
12 handles => {
13 _check_action_arguments => 'check',
14 },
15 );
16
17 has controller_instance => (
18 is => 'rw',
19 isa => 'Catalyst::Controller',
20 weak_ref => 1,
21 );
22
23 around match (Object $ctx) {
24
25 return
26 unless $self->$orig($ctx);
27 return 1
28 unless $self->method_type_constraint;
29
30 my @args = ($self->controller_instance, $ctx, @{ $ctx->req->args });
31 my $tc = $self->method_type_constraint;
32 my $ret = $self->_check_action_arguments(\@args);
33
34 return $ret;
5fb5cef1 35 }
36}