public
Created

lazy load attributes from role #moose #traits #lazy

  • Download Gist
gistfile1.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
use 5.014;
use Test::Most;
 
{ package Person;
use Moose;
with 'MooseX::Traits';
has name => qw( is ro required 1 lazy_build 1 );
}
 
{ package Identifiable;
use Moose::Role;
sub _build_name { 'John Doe' }
}
 
is( Person->new( name => 'Nelo Onyiah' )->name, 'Nelo Onyiah' );
is( Person->with_traits('Identifiable')->new->name, 'John Doe' );
 
done_testing;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.