6 use Test::More tests => 10;
11 This tests to make sure that the inlined constructor
12 has all the type constraints in order, even in the
13 cases when there is no type constraint available, such
14 as with a Class::MOP::Attribute object.
21 use Mouse::Util::TypeConstraints;
23 coerce 'Int' => from 'Str' => via { length $_ ? $_ : 69 };
25 has 'foo' => (is => 'rw', isa => 'Int');
26 has 'baz' => (is => 'rw', isa => 'Int');
27 has 'zot' => (is => 'rw', isa => 'Int', init_arg => undef);
28 has 'moo' => (is => 'rw', isa => 'Int', coerce => 1, default => '', required => 1);
29 has 'boo' => (is => 'rw', isa => 'Int', coerce => 1, builder => '_build_boo', required => 1);
33 Foo->meta->add_attribute(
34 Mouse::Meta::Attribute->new(
43 my $is_immutable = Foo->meta->is_immutable;
44 my $mutable_string = $is_immutable ? 'immutable' : 'mutable';
46 my $f = Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => 4);
47 is($f->moo, 69, "Type coercion works as expected on default ($mutable_string)");
48 is($f->boo, 69, "Type coercion works as expected on builder ($mutable_string)");
49 } "... this passes the constuctor correctly ($mutable_string)";
52 Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => "not an int");
53 } "... the constructor doesn't care about 'zot' ($mutable_string)";
56 Foo->new(foo => "Hello World", bar => 100, baz => "Hello World");
57 } "... this fails the constuctor correctly ($mutable_string)";
59 Foo->meta->make_immutable(debug => 0) unless $is_immutable;