5 use Method::Generate::Constructor;
6 use Method::Generate::Accessor;
8 my $gen = Method::Generate::Constructor->new(
9 accessor_generator => Method::Generate::Accessor->new
12 $gen->generate_method('Foo', 'new', {
14 two => { init_arg => undef },
15 three => { init_arg => 'THREE' }
18 my $first = Foo->new({
27 { %$first }, { one => 1, three => 3 },
28 'init_arg handling ok'
31 $gen->generate_method('Bar', 'new' => {
32 one => { required => 1 },
33 three => { init_arg => 'THREE', required => 1 }
37 exception { Bar->new },
38 qr/Missing required arguments: THREE, one/,
39 'two missing args reported correctly'
43 exception { Bar->new(THREE => 3) },
44 qr/Missing required arguments: one/,
45 'one missing arg reported correctly'
49 exception { Bar->new(one => 1, THREE => 3) },
51 'pass with both required args'
55 exception { Bar->new({ one => 1, THREE => 3 }) },
57 'hashrefs also supported'
61 exception { $first->new(one => 1, THREE => 3) },
63 'calling ->new on an object works'