Moose now warns when you try to load it from the main package. Added a
[gitmo/Moose.git] / t / 300_immutable / 004_inlined_constructors_n_types.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 3;
7 use Test::Exception;
8
9
10
11 =pod
12
13 This tests to make sure that the inlined constructor
14 has all the type constraints in order, even in the 
15 cases when there is no type constraint available, such 
16 as with a Class::MOP::Attribute object.
17
18 =cut
19
20 {
21     package Foo;
22     use Moose;
23
24     has 'foo' => (is => 'rw', isa => 'Int');    
25     has 'baz' => (is => 'rw', isa => 'Int');
26     has 'zot' => (is => 'rw', isa => 'Int', init_arg => undef);
27     
28     Foo->meta->add_attribute(
29         Class::MOP::Attribute->new(
30             'bar' => (
31                 accessor => 'bar',
32             )
33         )
34     );
35     
36     Foo->meta->make_immutable(debug => 0);
37 }
38
39 lives_ok {
40     Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => 4);
41 } '... this passes the constuctor correctly';
42
43 lives_ok {
44     Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => "not an int");
45 } "... the constructor doesn't care about 'zot'";
46
47 dies_ok {
48     Foo->new(foo => "Hello World", bar => 100, baz => "Hello World");
49 } '... this fails the constuctor correctly';
50
51
52
53