3 role CatalystX::Declare::Controller::Meta::TypeConstraintMapping {
5 use MooseX::Types::Moose qw( HashRef Object ArrayRef Str CodeRef );
7 use aliased 'Moose::Meta::TypeConstraint';
8 use aliased 'MooseX::Method::Signatures::Meta::Method', 'MethodWithSignature';
10 has method_type_constraint_map => (
11 metaclass => 'Collection::Hash',
13 isa => HashRef[Object],
17 'get_method_type_constraint' => 'get',
18 'set_method_type_constraint' => 'set,
22 has method_named_param_map => (
23 metaclass => 'Collection::Hash',
25 isa => HashRef[ArrayRef[Str]],
29 'get_method_named_params' => 'get',
30 'set_method_named_params' => 'set',
34 has method_named_type_constraint_map => (
35 metaclass => 'Collection::Hash',
37 isa => HashRef[HashRef[Object]],
41 'get_method_named_type_constraint' => 'get',
42 'set_method_named_type_constraint' => 'set',
46 method _build_method_type_constraint_map {
50 method _build_method_named_type_constraint_map {
54 method _build_method_named_param_map {
58 around add_method ($method_name, $method) {
60 if (is_Object $method and $method->isa(MethodWithSignature)) {
62 my $tc = $method->type_constraint;
64 $self->set_method_type_constraint(
69 if ($method->parsed_signature->has_named_params) {
70 my $named = $method->parsed_signature->named_params;
72 $self->set_method_named_params(
74 [ map $_->label, @$named ],
76 $self->set_method_named_type_constraint(
78 { map +($_->label, $_->meta_type_constraint), @$named },
83 return $self->$orig($method_name, $method);
86 method _find_capable_classes (CodeRef $test) {
89 grep { local $_ = $_; $_->$test }
92 grep { $_->can('meta') }
93 $self->linearized_isa;
96 method find_method_named_params (Str $name) {
98 my @parents = $self->_find_capable_classes(sub { $_->can('get_method_named_params') });
100 for my $isa (@parents) {
102 if (my $named = $isa->get_method_named_params($name)) {
110 method find_method_named_type_constraint (Str $method, Str $param) {
112 my @parents = $self->_find_capable_classes(sub { $_->can('get_method_named_type_constraint') });
114 for my $isa (@parents) {
116 if (my $named = $isa->get_method_named_type_constraint($method)) {
117 return $named->{ $param };
124 method find_method_type_constraint (Str $name) {
126 my @parents = $self->_find_capable_classes(sub { $_->can('get_method_type_constraint') });
128 for my $isa (@parents) {
130 if (my $tc = $isa->get_method_type_constraint($name)) {