X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F08-role-composition.t;fp=t%2F08-role-composition.t;h=f4b7f36ee821c1c09bb4af3dc70f15a569b46a8f;hb=d7ebfe7871af833331ba23b96ce7194254470804;hp=81eeb4415fd1352a18e86d835de2a2dfa8587aa9;hpb=a9d2b1a78f09fa9f0413953fb089ba0918e5da13;p=gitmo%2FMooseX-ClassAttribute.git diff --git a/t/08-role-composition.t b/t/08-role-composition.t index 81eeb44..f4b7f36 100644 --- a/t/08-role-composition.t +++ b/t/08-role-composition.t @@ -14,6 +14,16 @@ use Test::More; isa => 'HashRef', default => sub { {} }, ); + + class_has 'lazy_fail' => ( + isa => 'Int' + , is => 'ro' + , lazy => 1 + , default => sub { + my $self = shift; + $self->life + 42; + } + ); } { @@ -24,13 +34,31 @@ use Test::More; { package Bar; use Moose; + use MooseX::ClassAttribute; with( 'Role2', 'Role' ); + + class_has 'life' => ( isa => 'Int', is => 'ro', default => 42 ); } { local $TODO = 'Class attributes are lost during role composition'; can_ok( 'Bar', 'CA', ); + my $obj; + eval { + $obj = Bar->new; + }; + ok( !$@, 'No errors creating object' ); + is( $obj->life, 42, 'Right value for object' ); + eval { + $obj->lazy_fail; + }; + ok (!$@, "Calling class attribute declared in role syyucceeded" ); + + eval { + $obj->lazy_fail = 84 ? return : die "Not equal"; + }; + ok (!$@, "Lazy class attribute in role was able to utilize non-lazy values in base class" ); } done_testing();