3 role CatalystX::Declare::Controller::ActionPreparation {
5 use aliased 'CatalystX::Declare::Action::CatchValidationError';
6 use aliased 'CatalystX::Declare::Dispatching::ChainTypeSensitivity';
9 method _apply_action_roles (Object $action, @roles) {
11 for my $role (CatchValidationError, @roles) {
12 my $fq_role = $self->_qualify_class_name(ActionRole => $role);
14 Class::MOP::load_class($fq_role);
15 $fq_role->meta->apply($action);
19 method _find_method_type_constraint (Str $name) {
21 $self->meta->find_method_type_constraint($name)
23 my $method = $self->meta->find_method_by_name($name);
24 ( $_ = $method->can('type_constraint') )
30 method _ensure_applied_dispatchtype_roles {
32 my $type = $self->_app->dispatcher->dispatch_type('Chained');
35 if $type->DOES(ChainTypeSensitivity);
37 my $immutable = $type->meta->is_immutable;
38 my %immutable_options;
40 %immutable_options = $type->meta->immutable_options;
41 $type->meta->make_mutable;
44 # FIXME we really shouldn't have to tweak the dispatch type
45 ChainTypeSensitivity->meta->apply($type->meta);
47 $type->meta->make_immutable(%immutable_options)
51 after register_actions {
53 $self->_ensure_applied_dispatchtype_roles;
56 around create_action (%args) {
58 my @action_roles = @{ delete($args{attributes}{CatalystX_Declarative_ActionRoles}) || [] };
60 my $action = $self->$orig(%args);
63 if $args{attributes}{Private};
65 $self->_apply_action_roles($action, @action_roles);
68 unless $action->DOES(CatchValidationError);
70 my $tc = $self->_find_method_type_constraint($action->name);
75 $action->method_type_constraint($tc);
76 $action->controller_instance($self);