X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeCoercion.pm;h=6ecafba3acf51b145b320b8e479cb781de6feace;hb=HEAD;hp=8b73ca1298a5f39a7df9eebd4ed89d0cc0431e35;hpb=74397c13ad55fc865db34721aed512d4f605fadf;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeCoercion.pm b/lib/Moose/Meta/TypeCoercion.pm index 8b73ca1..6ecafba 100644 --- a/lib/Moose/Meta/TypeCoercion.pm +++ b/lib/Moose/Meta/TypeCoercion.pm @@ -8,28 +8,27 @@ use metaclass; use Moose::Meta::Attribute; use Moose::Util::TypeConstraints (); -our $VERSION = '0.75_01'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - __PACKAGE__->meta->add_attribute('type_coercion_map' => ( reader => 'type_coercion_map', - default => sub { [] } + default => sub { [] }, + Class::MOP::_definition_context(), )); __PACKAGE__->meta->add_attribute( Moose::Meta::Attribute->new('type_constraint' => ( reader => 'type_constraint', - weak_ref => 1 + weak_ref => 1, + Class::MOP::_definition_context(), )) ); # private accessor __PACKAGE__->meta->add_attribute('compiled_type_coercion' => ( - accessor => '_compiled_type_coercion' + accessor => '_compiled_type_coercion', + Class::MOP::_definition_context(), )); -sub new { +sub new { my $class = shift; my $self = Class::MOP::class_of($class)->new_object(@_); $self->compile_type_coercion; @@ -49,22 +48,22 @@ sub compile_type_coercion { Moose->throw_error("Could not find the type constraint ($constraint_name) to coerce from"); } - push @coercions => [ - $type_constraint->_compiled_type_constraint, - $action + push @coercions => [ + $type_constraint->_compiled_type_constraint, + $action ]; } - $self->_compiled_type_coercion(sub { + $self->_compiled_type_coercion(sub { my $thing = shift; foreach my $coercion (@coercions) { my ($constraint, $converter) = @$coercion; if ($constraint->($thing)) { - local $_ = $thing; + local $_ = $thing; return $converter->($thing); } } return $thing; - }); + }); } sub has_coercion_for_type { @@ -75,12 +74,12 @@ sub has_coercion_for_type { sub add_type_coercions { my ($self, @new_coercion_map) = @_; - - my $coercion_map = $self->type_coercion_map; + + my $coercion_map = $self->type_coercion_map; my %has_coercion = @$coercion_map; - + while (@new_coercion_map) { - my ($constraint_name, $action) = splice(@new_coercion_map, 0, 2); + my ($constraint_name, $action) = splice(@new_coercion_map, 0, 2); if ( exists $has_coercion{$constraint_name} ) { require Moose; @@ -89,7 +88,7 @@ sub add_type_coercions { push @{$coercion_map} => ($constraint_name, $action); } - + # and re-compile ... $self->compile_type_coercion; } @@ -99,14 +98,12 @@ sub coerce { $_[0]->_compiled_type_coercion->($_[1]) } 1; +# ABSTRACT: The Moose Type Coercion metaclass + __END__ =pod -=head1 NAME - -Moose::Meta::TypeCoercion - The Moose Type Coercion metaclass - =head1 DESCRIPTION A type coercion object is basically a mapping of one or more type @@ -174,21 +171,6 @@ This will return a L instance for this class. =head1 BUGS -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Stevan Little Estevan@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. +See L for details on reporting bugs. =cut