X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FAttribute.pm;h=af9e737602b1377a6048b6c5003d361bf42da1e3;hb=f7b11a21869769d2b49bba4fa72d33fa54ad0c2e;hp=9176bd0848abae1244aae137316a4e6b03d4096b;hpb=bb73340585512b0e09519eea54480ea3729ebf0b;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 9176bd0..af9e737 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -10,14 +10,28 @@ 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 !exists($args{builder}); + if ($name =~ /^_/) { + $args{clearer} = "_clear${name}" if !exists($args{clearer}); + $args{predicate} = "_has${name}" if !exists($args{predicate}); + } + else { + $args{clearer} = "clear_${name}" if !exists($args{clearer}); + $args{predicate} = "has_${name}" if !exists($args{predicate}); + } } bless \%args, $class; @@ -29,6 +43,7 @@ sub _is_metadata { $_[0]->{is} } sub is_required { $_[0]->{required} } sub default { $_[0]->{default} } sub is_lazy { $_[0]->{lazy} } +sub is_lazy_build { $_[0]->{lazy_build} } sub predicate { $_[0]->{predicate} } sub clearer { $_[0]->{clearer} } sub handles { $_[0]->{handles} } @@ -356,6 +371,8 @@ installed. Some error checking is done. =head2 has_builder -> Bool +=head2 is_lazy_build => Bool + =head2 should_auto_deref -> Bool Informational methods. @@ -386,5 +403,15 @@ this attribute's type constraint; Checks that the given value passes this attribute's type constraint. Returns 1 on success, otherwise Ces. +=head2 clone_parent OwnerClass, AttributeName, %args -> Mouse::Meta::Attribute + +Creates a new attribute in OwnerClass, inheriting options from parent classes. +Accessors and helper methods are installed. Some error checking is done. + +=head2 get_parent_args OwnerClass, AttributeName -> Hash + +Returns the options that the parent class of C used for attribute +C. + =cut