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.
19 =head add_type_coercions
21 method modification to throw exception should we try to add a coercion on a
22 dependent type that's had it's constraining value filled
26 around 'add_type_coercions' => sub {
27 my ($add_type_coercions, $self, @args) = @_;
28 if($self->type_constraint->has_constraining_value) {
29 Moose->throw_error("Cannot add type coercions to a dependent type constraint that's been defined.");
31 return $self->$add_type_coercions(@args);
36 ## These two are here until I can merge change upstream to Moose
39 my $coderef = $self->_compiled_type_coercion;
40 return $coderef->(@_);
43 sub compile_type_coercion {
45 my @coercion_map = @{$self->type_coercion_map};
47 while (@coercion_map) {
48 my ($constraint_name, $action) = splice(@coercion_map, 0, 2);
49 my $type_constraint = ref $constraint_name ? $constraint_name : Moose::Util::TypeConstraints::find_or_parse_type_constraint($constraint_name);
51 unless ( defined $type_constraint ) {
53 Moose->throw_error("Could not find the type constraint ($constraint_name) to coerce from");
57 $type_constraint->_compiled_type_constraint,
61 $self->_compiled_type_coercion(sub {
63 foreach my $coercion (@coercions) {
64 my ($constraint, $converter) = @$coercion;
65 if ($constraint->($thing)) {
67 return $converter->($thing, @_);
76 The following modules or resources may be of interest.
78 L<Moose>, L<Moose::Meta::TypeCoercion>
82 John Napiorkowski, C<< <jjnapiork@cpan.org> >>
84 =head1 COPYRIGHT & LICENSE
86 This program is free software; you can redistribute it and/or modify
87 it under the same terms as Perl itself.
91 __PACKAGE__->meta->make_immutable;