added test from #62467
[gitmo/MooseX-ClassAttribute.git] / t / 08-role-composition.t
index 81eeb44..f4b7f36 100644 (file)
@@ -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();