]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Meta/TypeConstraint/Autocoerce.pm
Fix and test parent validation in LT::Meta::TC::Autocoerce
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Meta / TypeConstraint / Autocoerce.pm
index 136940d23d3008f3e32dd7549af9444a6efce074..c31508b41f6d80dc82aab3e88ecaa80f1eabc33a 100644 (file)
@@ -9,11 +9,11 @@ LaTeX::TikZ::Meta::TypeConstraint::Autocoerce - Type constraint metaclass that a
 
 =head1 VERSION
 
-Version 0.01
+Version 0.02
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 =head1 SYNOPSIS
 
@@ -76,7 +76,7 @@ our $VERSION = '0.01';
 
 =head1 DESCRIPTION
 
-This type constraint metaclass tries to autoload a specific module when a type coercion is attempted, which is supposed to contain the actual coercion code.
+When a type coercion is attempted, this type constraint metaclass tries to autoload a specific module which is supposed to contain the actual coercion code.
 This allows you to declare types that can be replaced (through coercion) at the end user's discretion.
 
 It works with both L<Moose> and L<Mouse> by using L<Any::Moose>.
@@ -89,8 +89,9 @@ use Scalar::Util qw/blessed/;
 
 use Sub::Name ();
 
+use LaTeX::TikZ::Tools;
+
 use Any::Moose;
-use Any::Moose 'Util' => [ 'find_meta' ];
 
 =head1 RELATIONSHIPS
 
@@ -163,10 +164,10 @@ around 'new' => sub {
  }
 
  my $parent = delete $args{parent};
- unless (defined $parent and blessed $parent) {
-  $parent = find_meta($parent);
-  Carp::confess("No meta object for parent $parent");
-  $parent = $parent->type_constraint;
+ 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;
  }
  __PACKAGE__->meta->find_attribute_by_name('parent')
                   ->type_constraint->assert_valid($parent);