Properly delegate coercions for Optional[].
[gitmo/MooseX-Types-Structured.git] / lib / MooseX / Meta / TypeCoercion / Structured / Optional.pm
1 package MooseX::Meta::TypeCoercion::Structured::Optional;
2
3 use Moose;
4 extends 'Moose::Meta::TypeCoercion';
5
6 sub compile_type_coercion {
7     my ($self) = @_;
8     my $constraint = $self->type_constraint->type_parameter;
9
10     $self->_compiled_type_coercion(sub {
11         my ($value) = @_;
12         return unless $constraint->has_coercion;
13         return $constraint->coerce($value);
14     });
15 }
16
17 sub has_coercion_for_type { 0 }
18
19 sub add_type_coercions {
20     Moose->throw_error("Cannot add additional type coercions to Optional types");
21 }
22
23 __PACKAGE__->meta->make_immutable(inline_constructor => 0);
24
25 1;