3 role CatalystX::Declare::Controller::ActionPreparation {
5 use aliased 'CatalystX::Declare::Action::CatchValidationError';
6 use aliased 'CatalystX::Declare::Dispatching::ChainTypeSensitivity';
8 method _find_method_type_constraint (Str $name) {
10 $self->meta->find_method_type_constraint($name)
12 my $method = $self->meta->find_method_by_name($name);
13 ( $_ = $method->can('type_constraint') )
19 method _find_method_named_params (Str $name) {
21 return $self->meta->find_method_named_params($name);
24 method _find_method_named_type_constraint (Str $method, Str $param) {
26 return $self->meta->find_method_named_type_constraint($method, $param);
29 method _ensure_applied_dispatchtype_roles {
31 my $type = $self->_app->dispatcher->dispatch_type('Chained');
34 if $type->DOES(ChainTypeSensitivity);
36 my $immutable = $type->meta->is_immutable;
37 my %immutable_options;
39 %immutable_options = $type->meta->immutable_options;
40 $type->meta->make_mutable;
43 # FIXME we really shouldn't have to tweak the dispatch type
44 ChainTypeSensitivity->meta->apply($type->meta);
46 $type->meta->make_immutable(%immutable_options)
50 after register_actions {
52 $self->_ensure_applied_dispatchtype_roles;
55 around gather_action_roles(%args) {
58 @{ delete($args{attributes}{CatalystX_Declarative_ActionRoles}) || [] },
62 around create_action (%args) {
63 my $action = $self->$orig(%args);
66 if $args{attributes}{Private};
69 unless $action->DOES(CatchValidationError);
71 my $tc = $self->_find_method_type_constraint($action->name);
72 my $np = $self->_find_method_named_params($action->name);
77 $action->controller_instance($self);
78 $action->method_type_constraint($tc);
82 $action->method_named_params($np);
83 $action->method_named_type_constraint({
84 map +($_, $self->_find_method_named_type_constraint($action->name, $_)),