2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
10 $TODO = q{Mouse is not yet completed};
12 use Scalar::Util 'blessed';
14 use Mouse::Util::TypeConstraints;
29 has lazy_classname => (
32 default => sub { "Parent" },
35 has type_constrained => (
49 has '+lazy_classname' => (
50 default => sub { "Child" },
53 has '+type_constrained' => (
59 my $foo = Parent->new;
60 my $bar = Parent->new;
62 is(blessed($foo), 'Parent', 'Parent->new gives a Parent object');
63 is($foo->name, undef, 'No name yet');
64 is($foo->lazy_classname, 'Parent', "lazy attribute initialized");
65 lives_ok { $foo->type_constrained(10.5) } "Num type constraint for now..";
67 # try to rebless, except it will fail due to Child's stricter type constraint
68 throws_ok { Child->meta->rebless_instance($foo) }
69 qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/,
70 '... this failed cause of type check';
71 throws_ok { Child->meta->rebless_instance($bar) }
72 qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 5\.5/,
73 '... this failed cause of type check';;
75 $foo->type_constrained(10);
76 $bar->type_constrained(5);
78 Child->meta->rebless_instance($foo);
79 Child->meta->rebless_instance($bar);
81 is(blessed($foo), 'Child', 'successfully reblessed into Child');
82 is($foo->name, 'Junior', "Child->name's default came through");
84 is($foo->lazy_classname, 'Parent', "lazy attribute was already initialized");
85 is($bar->lazy_classname, 'Child', "lazy attribute just now initialized");
87 throws_ok { $foo->type_constrained(10.5) }
88 qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/,
89 '... this failed cause of type check';