Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Created February 23, 2012 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j1n3l0/1895022 to your computer and use it in GitHub Desktop.
Save j1n3l0/1895022 to your computer and use it in GitHub Desktop.
lazy load attributes from role #moose #traits #lazy
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment