From: Yuval Kogman Date: Mon, 16 Jun 2008 21:51:47 +0000 (+0000) Subject: implement lazy_build X-Git-Tag: 0.04~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=45959ffa208c3156f08f985f42b814fce8559283;p=gitmo%2FMouse.git implement lazy_build --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index ff1a3ff..733c129 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -12,8 +12,14 @@ sub new { $args{init_arg} = $args{name} unless exists $args{init_arg}; + $args{is} ||= ''; + if ( $args{lazy_build} ) { + $args{lazy} = 1; + $args{builder} ||= "_build_$args{name}"; + } + bless \%args, $class; } diff --git a/t/023-builder.t b/t/023-builder.t index 25b7fa8..a72f900 100644 --- a/t/023-builder.t +++ b/t/023-builder.t @@ -25,12 +25,11 @@ do { }; has age => ( - is => 'ro', - isa => 'Int', - builder => '_build_age', - lazy => 1, - clearer => 'clear_age', - predicate => 'has_age', + is => 'ro', + isa => 'Int', + lazy_build => 1, + clearer => 'clear_age', + predicate => 'has_age', ); sub default_age { 20 }