Commit | Line | Data |
abd193e2 |
1 | package MooseX::Meta::TypeCoercion::Structured::Optional; |
2 | |
3 | use Moose; |
4 | extends 'Moose::Meta::TypeCoercion'; |
5 | |
8dbdca20 |
6 | =method compile_type_coercion |
7 | |
8 | =cut |
9 | |
abd193e2 |
10 | sub compile_type_coercion { |
11 | my ($self) = @_; |
12 | my $constraint = $self->type_constraint->type_parameter; |
13 | |
14 | $self->_compiled_type_coercion(sub { |
15 | my ($value) = @_; |
16 | return unless $constraint->has_coercion; |
17 | return $constraint->coerce($value); |
18 | }); |
19 | } |
20 | |
21 | sub has_coercion_for_type { 0 } |
22 | |
23 | sub add_type_coercions { |
24 | Moose->throw_error("Cannot add additional type coercions to Optional types"); |
25 | } |
26 | |
27 | __PACKAGE__->meta->make_immutable(inline_constructor => 0); |
28 | |
29 | 1; |