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