]> 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 f335cb95f108fd787c4a82a5efba913713f43bdf..c31508b41f6d80dc82aab3e88ecaa80f1eabc33a 100644 (file)
@@ -76,7 +76,7 @@ our $VERSION = '0.02';
 
 =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);