6 use Test::More tests => 23;
19 my ($self, $value, $callback, $attr) = @_;
21 ::isa_ok($attr, 'Mouse::Meta::Attribute');
22 ::is($attr->name, 'foo', '... got the right name');
24 $callback->($value * 2);
29 reader => 'get_lazy_foo',
33 my ($self, $value, $callback, $attr) = @_;
35 ::isa_ok($attr, 'Mouse::Meta::Attribute');
36 ::is($attr->name, 'lazy_foo', '... got the right name');
38 $callback->($value * 2);
42 has 'lazy_foo_w_type' => (
43 reader => 'get_lazy_foo_w_type',
48 my ($self, $value, $callback, $attr) = @_;
50 ::isa_ok($attr, 'Mouse::Meta::Attribute');
51 ::is($attr->name, 'lazy_foo_w_type', '... got the right name');
53 $callback->($value * 2);
57 has 'lazy_foo_builder' => (
58 reader => 'get_lazy_foo_builder',
59 builder => 'get_foo_builder',
61 my ($self, $value, $callback, $attr) = @_;
63 ::isa_ok($attr, 'Mouse::Meta::Attribute');
64 ::is($attr->name, 'lazy_foo_builder', '... got the right name');
66 $callback->($value * 2);
70 has 'lazy_foo_builder_w_type' => (
71 reader => 'get_lazy_foo_builder_w_type',
73 builder => 'get_foo_builder_w_type',
75 my ($self, $value, $callback, $attr) = @_;
77 ::isa_ok($attr, 'Mouse::Meta::Attribute');
78 ::is($attr->name, 'lazy_foo_builder_w_type', '... got the right name');
80 $callback->($value * 2);
84 sub get_foo_builder { 100 }
85 sub get_foo_builder_w_type { 1000 }
89 my $foo = Foo->new(foo => 10);
92 is($foo->get_foo, 20, 'initial value set to 2x given value');
93 is($foo->get_lazy_foo, 20, 'initial lazy value set to 2x given value');
94 is($foo->get_lazy_foo_w_type, 40, 'initial lazy value with type set to 2x given value');
95 is($foo->get_lazy_foo_builder, 200, 'initial lazy value with builder set to 2x given value');
96 is($foo->get_lazy_foo_builder_w_type, 2000, 'initial lazy value with builder and type set to 2x given value');
107 my ($self, $value, $callback, $attr) = @_;
109 ::isa_ok($attr, 'Mouse::Meta::Attribute');
110 ::is($attr->name, 'foo', '... got the right name');
112 $callback->($value * 2);
116 __PACKAGE__->meta->make_immutable;
120 my $bar = Bar->new(foo => 10);
123 is($bar->get_foo, 20, 'initial value set to 2x given value');
135 my ($self, $value, $callback, $attr) = @_;
137 ::isa_ok($attr, 'Mouse::Meta::Attribute');
138 ::is($attr->name, 'foo', '... got the right name');
140 $callback->("Hello $value World");
144 __PACKAGE__->meta->make_immutable;
148 Fail::Bar->new(foo => 10)
149 } '... this fails, because initializer returns a bad type';