Convert from Module::Install to Dist::Zilla
[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
8dbdca20 6=method compile_type_coercion
7
8=cut
9
abd193e2 10sub 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
21sub has_coercion_for_type { 0 }
22
23sub 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
291;