4 use Test::More tests => 15;
15 default => sub { ++$lazy_run },
16 predicate => 'has_lazy',
20 can_ok(Class => 'has_lazy');
22 my $object = Class->new;
23 is($lazy_run, 0, "lazy attribute not yet initialized");
25 ok(!$object->has_lazy, "no lazy value yet");
26 is($lazy_run, 0, "lazy attribute not initialized by predicate");
28 is($object->lazy, 1, "lazy value");
29 is($lazy_run, 1, "lazy coderef invoked once");
31 ok($object->has_lazy, "lazy value now");
32 is($lazy_run, 1, "lazy coderef invoked once");
34 is($object->lazy, 1, "lazy value is cached");
35 is($lazy_run, 1, "lazy coderef invoked once");
37 my $object2 = Class->new(lazy => 'very');
38 is($lazy_run, 1, "lazy attribute not initialized when an argument is passed to the constructor");
40 ok($object2->has_lazy, "lazy value now");
41 is($lazy_run, 1, "lazy attribute not initialized when checked with predicate");
43 is($object2->lazy, 'very', 'value from the constructor');
44 is($lazy_run, 1, "lazy coderef not invoked, we already have a value");