prepare for 0.011
[catagits/CatalystX-Declare.git] / lib / CatalystX / Declare / Controller / Meta / TypeConstraintMapping.pm
CommitLineData
392e5076 1use MooseX::Declare;
2use MooseX::AttributeHelpers;
3
4role CatalystX::Declare::Controller::Meta::TypeConstraintMapping {
5
6 use MooseX::Types::Moose qw( HashRef Object );
7
8 use aliased 'Moose::Meta::TypeConstraint';
9 use aliased 'MooseX::Method::Signatures::Meta::Method', 'MethodWithSignature';
10
11 has method_type_constraint_map => (
12 metaclass => 'Collection::Hash',
13 is => 'ro',
14 isa => HashRef[Object],
15 required => 1,
16 lazy_build => 1,
17 provides => {
18 get => 'get_method_type_constraint',
19 set => 'set_method_type_constraint',
20 },
21 );
22
23 method _build_method_type_constraint_map {
24 return +{};
25 }
26
27 around add_method ($method_name, $method) {
28
29 if (is_Object $method and $method->isa(MethodWithSignature)) {
30
31 my $tc = $method->type_constraint;
32
33 $self->set_method_type_constraint(
34 $method_name,
35 $tc,
36 );
37 }
38
39 return $self->$orig($method_name, $method);
40 }
41
42 method find_method_type_constraint (Str $name) {
43
44 my @parents =
45 grep { $_->can('get_method_type_constraint') }
46 map { $_->meta }
47 grep { $_->can('meta') }
48 $self->linearized_isa;
49
50 for my $isa ($self, @parents) {
51
52 if (my $tc = $isa->get_method_type_constraint($name)) {
53 return $tc;
54 }
55 }
56
57 return undef;
58 }
59}
60