use Sub::Name ();
+use LaTeX::TikZ::Tools;
+
use Any::Moose;
-use Any::Moose 'Util' => [ 'find_meta' ];
=head1 RELATIONSHIPS
}
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);
use strict;
use warnings;
-use Test::More tests => 7 * 4;
+use Test::More tests => 3 + 7 * 4;
use lib 't/lib';
use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce;
+{
+ my $tc = eval {
+ LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new(
+ parent => undef,
+ );
+ };
+ like $@, qr/^No meta object for undefined parent/, 'Undef parent';
+}
+
+{
+ my $parent = 'LaTeX::TikZ::A::Class::Likely::Not::To::Exist';
+ my $tc = eval {
+ LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new(
+ parent => $parent,
+ );
+ };
+ like $@, qr/^No meta object for parent \Q$parent\E/, 'Nonexistent parent';
+}
+
+{
+ my $tc = eval {
+ LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new(
+ parent => 'LaTeX::TikZ::Meta::TypeConstraint::Autocoerce',
+ );
+ };
+ is $@, '', 'Valid parent';
+}
+
{
package LaTeX::TikZ::TestX;