4 use Test::More tests => 16;
16 default => sub { ++$lazy_run },
26 has lazy_no_default => (
30 } qr/You cannot have lazy attribute \(lazy_no_default\) without specifying a default value for it/;
33 my $object = Class->new;
34 is($lazy_run, 0, "lazy attribute not yet initialized");
36 is($object->lazy, 1, "lazy coderef");
37 is($lazy_run, 1, "lazy coderef invoked once");
39 is($object->lazy, 1, "lazy coderef is cached");
40 is($lazy_run, 1, "lazy coderef invoked once");
42 is($object->lazy_value, 'welp', "lazy value");
43 is($lazy_run, 1, "lazy coderef invoked once");
45 is($object->lazy_value("newp"), "newp", "set new value");
46 is($lazy_run, 1, "lazy coderef invoked once");
48 is($object->lazy_value, "newp", "got new value");
49 is($lazy_run, 1, "lazy coderef invoked once");
51 my $object2 = Class->new(lazy => 'very', lazy_value => "heh");
52 is($lazy_run, 1, "lazy attribute not initialized when an argument is passed to the constructor");
54 is($object2->lazy, 'very', 'value from the constructor');
55 is($object2->lazy_value, 'heh', 'value from the constructor');
56 is($lazy_run, 1, "lazy coderef not invoked, we already have a value");