6 use Test::More tests => 24;
21 my ($self, $value, $callback, $attr) = @_;
23 ::isa_ok($attr, 'Moose::Meta::Attribute');
24 ::is($attr->name, 'foo', '... got the right name');
26 $callback->($value * 2);
31 reader => 'get_lazy_foo',
35 my ($self, $value, $callback, $attr) = @_;
37 ::isa_ok($attr, 'Moose::Meta::Attribute');
38 ::is($attr->name, 'lazy_foo', '... got the right name');
40 $callback->($value * 2);
44 has 'lazy_foo_w_type' => (
45 reader => 'get_lazy_foo_w_type',
50 my ($self, $value, $callback, $attr) = @_;
52 ::isa_ok($attr, 'Moose::Meta::Attribute');
53 ::is($attr->name, 'lazy_foo_w_type', '... got the right name');
55 $callback->($value * 2);
59 has 'lazy_foo_builder' => (
60 reader => 'get_lazy_foo_builder',
61 builder => 'get_foo_builder',
63 my ($self, $value, $callback, $attr) = @_;
65 ::isa_ok($attr, 'Moose::Meta::Attribute');
66 ::is($attr->name, 'lazy_foo_builder', '... got the right name');
68 $callback->($value * 2);
72 has 'lazy_foo_builder_w_type' => (
73 reader => 'get_lazy_foo_builder_w_type',
75 builder => 'get_foo_builder_w_type',
77 my ($self, $value, $callback, $attr) = @_;
79 ::isa_ok($attr, 'Moose::Meta::Attribute');
80 ::is($attr->name, 'lazy_foo_builder_w_type', '... got the right name');
82 $callback->($value * 2);
86 sub get_foo_builder { 100 }
87 sub get_foo_builder_w_type { 1000 }
91 my $foo = Foo->new(foo => 10);
94 is($foo->get_foo, 20, 'initial value set to 2x given value');
95 is($foo->get_lazy_foo, 20, 'initial lazy value set to 2x given value');
96 is($foo->get_lazy_foo_w_type, 40, 'initial lazy value with type set to 2x given value');
97 is($foo->get_lazy_foo_builder, 200, 'initial lazy value with builder set to 2x given value');
98 is($foo->get_lazy_foo_builder_w_type, 2000, 'initial lazy value with builder and type set to 2x given value');
109 my ($self, $value, $callback, $attr) = @_;
111 ::isa_ok($attr, 'Moose::Meta::Attribute');
112 ::is($attr->name, 'foo', '... got the right name');
114 $callback->($value * 2);
118 metaclass->make_immutable;
122 my $bar = Bar->new(foo => 10);
125 is($bar->get_foo, 20, 'initial value set to 2x given value');
137 my ($self, $value, $callback, $attr) = @_;
139 ::isa_ok($attr, 'Moose::Meta::Attribute');
140 ::is($attr->name, 'foo', '... got the right name');
142 $callback->("Hello $value World");
146 metaclass->make_immutable;
150 Fail::Bar->new(foo => 10)
151 } '... this fails, because initializer returns a bad type';