From: Yuval Kogman Date: Tue, 17 Jun 2008 01:41:57 +0000 (+0000) Subject: lazy_build arg processing copied from Moose X-Git-Tag: 0.04~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2e7e86c63f956238494249295af0ea8b4489392e;p=gitmo%2FMouse.git lazy_build arg processing copied from Moose --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 9176bd0..a6b5f03 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -10,14 +10,27 @@ sub new { my $class = shift; my %args = @_; - $args{init_arg} = $args{name} + my $name = $args{name}; + + $args{init_arg} = $name unless exists $args{init_arg}; $args{is} ||= ''; - if ( $args{lazy_build} ) { - $args{lazy} = 1; - $args{builder} ||= "_build_$args{name}"; + if ($args{lazy_build}) { + confess("You can not use lazy_build and default for the same attribute $name") + if exists $args{default}; + $args{lazy} = 1; + $args{required} = 1; + $args{builder} ||= "_build_${name}"; + if ($name =~ /^_/) { + $args{clearer} ||= "_clear${name}"; + $args{predicate} ||= "_has${name}"; + } + else { + $args{clearer} ||= "clear_${name}"; + $args{predicate} ||= "has_${name}"; + } } bless \%args, $class;