Properly delegate coercions for Optional[].
[gitmo/MooseX-Types-Structured.git] / lib / MooseX / Meta / TypeCoercion / Structured / Optional.pm
CommitLineData
abd193e2 1package MooseX::Meta::TypeCoercion::Structured::Optional;
2
3use Moose;
4extends 'Moose::Meta::TypeCoercion';
5
6sub 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
17sub has_coercion_for_type { 0 }
18
19sub 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
251;