1 package ## Hide from PAUSE
2 MooseX::Dependent::Meta::TypeCoercion::Dependent;
5 extends 'Moose::Meta::TypeCoercion';
9 MooseX::Meta::TypeCoercion::Dependent - Coerce Dependent type constraints.
17 This class defines the following methods.
25 my $coderef = $self->_compiled_type_coercion;
26 return $coderef->(@_);
29 around 'add_type_coercions' => sub {
30 my ($add_type_coercions, $self, @args) = @_;
31 if($self->type_constraint->has_constraining_value) {
32 Moose->throw_error("Cannot add type coercions to a dependent type constraint that's been defined.");
34 return $self->$add_type_coercions(@args);
38 sub compile_type_coercion {
40 my @coercion_map = @{$self->type_coercion_map};
42 while (@coercion_map) {
43 my ($constraint_name, $action) = splice(@coercion_map, 0, 2);
44 my $type_constraint = ref $constraint_name ? $constraint_name : Moose::Util::TypeConstraints::find_or_parse_type_constraint($constraint_name);
46 unless ( defined $type_constraint ) {
48 Moose->throw_error("Could not find the type constraint ($constraint_name) to coerce from");
52 $type_constraint->_compiled_type_constraint,
56 $self->_compiled_type_coercion(sub {
58 foreach my $coercion (@coercions) {
59 my ($constraint, $converter) = @$coercion;
60 if ($constraint->($thing)) {
62 return $converter->($thing, @_);
74 The following modules or resources may be of interest.
76 L<Moose>, L<Moose::Meta::TypeCoercion>
80 John Napiorkowski, C<< <jjnapiork@cpan.org> >>
82 =head1 COPYRIGHT & LICENSE
84 This program is free software; you can redistribute it and/or modify
85 it under the same terms as Perl itself.
89 __PACKAGE__->meta->make_immutable;