From: Vincent Pit Date: Tue, 6 Aug 2013 14:29:13 +0000 (-0300) Subject: Rename LaTeX::TikZ::TypeConstraint::Autocoerce->parent into ->target X-Git-Tag: rt87282~4 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLaTeX-TikZ.git;a=commitdiff_plain;h=ecb1d1524df9ef8b8e0452d0de3efc871c3855e8 Rename LaTeX::TikZ::TypeConstraint::Autocoerce->parent into ->target Since the semantics of our parent attribute do not map exactly to those of Moose::Meta::TypeConstraint->parent, it is better to give it a different name. --- diff --git a/lib/LaTeX/TikZ/Meta/TypeConstraint/Autocoerce.pm b/lib/LaTeX/TikZ/Meta/TypeConstraint/Autocoerce.pm index 72bb96f..25f3879 100644 --- a/lib/LaTeX/TikZ/Meta/TypeConstraint/Autocoerce.pm +++ b/lib/LaTeX/TikZ/Meta/TypeConstraint/Autocoerce.pm @@ -30,7 +30,7 @@ our $VERSION = '0.02'; register_type_constraint( LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new( name => 'X::Autocoerce', - parent => find_type_constraint(__PACKAGE__), + target => find_type_constraint(__PACKAGE__), mapper => sub { join '::', __PACKAGE__, 'From', $_[1] }, ); ); @@ -123,15 +123,15 @@ has 'mapper' => ( required => 1, ); -=head2 C +=head2 C -A type constraint that defines which objects are already valid and do not need to be coerced. -This is somewhat different from L. +A type constraint that defines into what the objects are going to be coerced. +Objects satisfying this type constraint will be automatically considered as valid and will not be coerced. If it is given as a plain string, then a type constraint with the same name is searched for in the global type constraint registry. =cut -has 'parent' => ( +has 'target' => ( is => 'ro', isa => any_moose('Meta::TypeConstraint'), required => 1, @@ -139,7 +139,7 @@ has 'parent' => ( =head2 C -An optional user defined code reference which predates checking the parent for validity. +An optional user defined code reference which predates checking the target for validity. =cut @@ -150,9 +150,9 @@ has 'user_constraint' => ( =head1 METHODS -=head2 C<< new name => $name, mapper => $mapper, parent => $parent, [ user_constraint => sub { ... } ] >> +=head2 C<< new name => $name, mapper => $mapper, target => $target, [ user_constraint => sub { ... } ] >> -Constructs a type constraint object that will attempt to autocoerce objects that are not valid according to C<$parent> by loading the class returned by C<$mapper>. +Constructs a type constraint object that will attempt to autocoerce objects that are not valid according to C<$target> by loading the class returned by C<$mapper>. =cut @@ -160,18 +160,18 @@ around 'new' => sub { my ($orig, $class, %args) = @_; unless (exists $args{mapper}) { - $args{mapper} = sub { join '::', $_[0]->parent->name, $_[1] }; + $args{mapper} = sub { join '::', $_[0]->target->name, $_[1] }; } - my $parent = delete $args{parent}; - unless (blessed $parent) { - my $parent_name = defined $parent ? "parent $parent" : 'undefined parent'; - $parent = LaTeX::TikZ::Tools::type_constraint($parent) if defined $parent; - Carp::confess("No meta object for $parent_name") unless defined $parent; + my $target = delete $args{target}; + unless (blessed $target) { + my $target_name = defined $target ? "target $target" : 'undefined target'; + $target = LaTeX::TikZ::Tools::type_constraint($target) if defined $target; + Carp::confess("No meta object for $target_name") unless defined $target; } - __PACKAGE__->meta->find_attribute_by_name('parent') - ->type_constraint->assert_valid($parent); - $args{parent} = $parent; + __PACKAGE__->meta->find_attribute_by_name('target') + ->type_constraint->assert_valid($target); + $args{target} = $target; if (any_moose() eq 'Moose') { $args{coercion} = Moose::Meta::TypeCoercion->new; @@ -192,8 +192,8 @@ around 'new' => sub { return 1 if $ok; } - # Then, it's valid if and only if it passes the parent type constraint - return $tc->parent->check($thing); + # Then, it's valid if and only if it passes the target type constraint + return $tc->target->check($thing); }); $tc = $class->$orig(%args); diff --git a/lib/LaTeX/TikZ/Point.pm b/lib/LaTeX/TikZ/Point.pm index d5c5da0..01d562d 100644 --- a/lib/LaTeX/TikZ/Point.pm +++ b/lib/LaTeX/TikZ/Point.pm @@ -55,7 +55,7 @@ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; register_type_constraint( LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new( name => 'LaTeX::TikZ::Point::Autocoerce', - parent => find_type_constraint(__PACKAGE__), + target => find_type_constraint(__PACKAGE__), ), ); diff --git a/t/02-autocoerce.t b/t/02-autocoerce.t index ba05498..86d49cc 100644 --- a/t/02-autocoerce.t +++ b/t/02-autocoerce.t @@ -12,29 +12,29 @@ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; { my $tc = eval { LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new( - parent => undef, + target => undef, ); }; - like $@, qr/^No meta object for undefined parent/, 'Undef parent'; + like $@, qr/^No meta object for undefined target/, 'Undef target'; } { - my $parent = 'LaTeX::TikZ::A::Class::Likely::Not::To::Exist'; + my $target = 'LaTeX::TikZ::A::Class::Likely::Not::To::Exist'; my $tc = eval { LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new( - parent => $parent, + target => $target, ); }; - like $@, qr/^No meta object for parent \Q$parent\E/, 'Nonexistent parent'; + like $@, qr/^No meta object for target \Q$target\E/, 'Nonexistent target'; } { my $tc = eval { LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new( - parent => 'LaTeX::TikZ::Meta::TypeConstraint::Autocoerce', + target => 'LaTeX::TikZ::Meta::TypeConstraint::Autocoerce', ); }; - is $@, '', 'Valid parent'; + is $@, '', 'Valid target'; } { @@ -58,7 +58,7 @@ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; register_type_constraint( LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new( name => 'LaTeX::TikZ::TestX::Autocoerce', - parent => find_type_constraint(__PACKAGE__), + target => find_type_constraint(__PACKAGE__), mapper => sub { shift; my ($last) = $_[0] =~ /::([^:]+)$/;