X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FAttribute.pm;h=a6b5f03516f2313f260e932030a77db16bad02c5;hp=9176bd0848abae1244aae137316a4e6b03d4096b;hb=2e7e86c63f956238494249295af0ea8b4489392e;hpb=bb73340585512b0e09519eea54480ea3729ebf0b 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;