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;
14 This tests to make sure that the inlined constructor
15 has all the type constraints in order, even in the
16 cases when there is no type constraint available, such
17 as with a Mouse::Meta::Attribute object.
24 use Mouse::Util::TypeConstraints;
26 coerce 'Int' => from 'Str' => via { length $_ ? $_ : 69 };
28 has 'foo' => (is => 'rw', isa => 'Int');
29 has 'baz' => (is => 'rw', isa => 'Int');
30 has 'zot' => (is => 'rw', isa => 'Int', init_arg => undef);
31 has 'moo' => (is => 'rw', isa => 'Int', coerce => 1, default => '', required => 1);
32 has 'boo' => (is => 'rw', isa => 'Int', coerce => 1, builder => '_build_boo', required => 1);
36 Foo->meta->add_attribute(
37 Mouse::Meta::Attribute->new(
46 my $is_immutable = Foo->meta->is_immutable;
47 my $mutable_string = $is_immutable ? 'immutable' : 'mutable';
49 my $f = Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => 4);
50 is($f->moo, 69, "Type coercion works as expected on default ($mutable_string)");
51 is($f->boo, 69, "Type coercion works as expected on builder ($mutable_string)");
52 } "... this passes the constuctor correctly ($mutable_string)";
55 Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => "not an int");
56 } "... the constructor doesn't care about 'zot' ($mutable_string)";
59 Foo->new(foo => "Hello World", bar => 100, baz => "Hello World");
60 } "... this fails the constuctor correctly ($mutable_string)";
62 Foo->meta->make_immutable(debug => 0) unless $is_immutable;