18 my ($self, $value, $callback, $attr) = @_;
20 ::isa_ok($attr, 'Moose::Meta::Attribute');
21 ::is($attr->name, 'foo', '... got the right name');
23 $callback->($value * 2);
28 reader => 'get_lazy_foo',
32 my ($self, $value, $callback, $attr) = @_;
34 ::isa_ok($attr, 'Moose::Meta::Attribute');
35 ::is($attr->name, 'lazy_foo', '... got the right name');
37 $callback->($value * 2);
41 has 'lazy_foo_w_type' => (
42 reader => 'get_lazy_foo_w_type',
47 my ($self, $value, $callback, $attr) = @_;
49 ::isa_ok($attr, 'Moose::Meta::Attribute');
50 ::is($attr->name, 'lazy_foo_w_type', '... got the right name');
52 $callback->($value * 2);
56 has 'lazy_foo_builder' => (
57 reader => 'get_lazy_foo_builder',
58 builder => 'get_foo_builder',
60 my ($self, $value, $callback, $attr) = @_;
62 ::isa_ok($attr, 'Moose::Meta::Attribute');
63 ::is($attr->name, 'lazy_foo_builder', '... got the right name');
65 $callback->($value * 2);
69 has 'lazy_foo_builder_w_type' => (
70 reader => 'get_lazy_foo_builder_w_type',
72 builder => 'get_foo_builder_w_type',
74 my ($self, $value, $callback, $attr) = @_;
76 ::isa_ok($attr, 'Moose::Meta::Attribute');
77 ::is($attr->name, 'lazy_foo_builder_w_type', '... got the right name');
79 $callback->($value * 2);
83 sub get_foo_builder { 100 }
84 sub get_foo_builder_w_type { 1000 }
88 my $foo = Foo->new(foo => 10);
91 is($foo->get_foo, 20, 'initial value set to 2x given value');
92 is($foo->get_lazy_foo, 20, 'initial lazy value set to 2x given value');
93 is($foo->get_lazy_foo_w_type, 40, 'initial lazy value with type set to 2x given value');
94 is($foo->get_lazy_foo_builder, 200, 'initial lazy value with builder set to 2x given value');
95 is($foo->get_lazy_foo_builder_w_type, 2000, 'initial lazy value with builder and type set to 2x given value');
106 my ($self, $value, $callback, $attr) = @_;
108 ::isa_ok($attr, 'Moose::Meta::Attribute');
109 ::is($attr->name, 'foo', '... got the right name');
111 $callback->($value * 2);
115 __PACKAGE__->meta->make_immutable;
119 my $bar = Bar->new(foo => 10);
122 is($bar->get_foo, 20, 'initial value set to 2x given value');
134 my ($self, $value, $callback, $attr) = @_;
136 ::isa_ok($attr, 'Moose::Meta::Attribute');
137 ::is($attr->name, 'foo', '... got the right name');
139 $callback->("Hello $value World");
143 __PACKAGE__->meta->make_immutable;
147 Fail::Bar->new(foo => 10)
148 } '... this fails, because initializer returns a bad type';