X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FClass.pm;h=8e89567673f0389743dbd1164f7b65cfe8bc3f9a;hp=07b54e7aa211cbdc3d96202ece664a071e63b545;hb=60f6eba91f12d48fa30a8e16abe2db8c95b4d878;hpb=bfcc8a055b739e04da20df0069a9ad329b9429cf diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 07b54e7..8e89567 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -98,9 +98,35 @@ sub get_all_method_names { sub add_attribute { my $self = shift; - my $attr = shift; - $self->{'attributes'}{$attr->name} = $attr; + if (@_ == 1 && blessed($_[0])) { + my $attr = shift @_; + $self->{'attributes'}{$attr->name} = $attr; + } else { + my $names = shift @_; + $names = [$names] if !ref($names); + my $metaclass = 'Mouse::Meta::Attribute'; + my %options = @_; + + if ( my $metaclass_name = delete $options{metaclass} ) { + my $new_class = Mouse::Util::resolve_metaclass_alias( + 'Attribute', + $metaclass_name + ); + if ( $metaclass ne $new_class ) { + $metaclass = $new_class; + } + } + + for my $name (@$names) { + if ($name =~ s/^\+//) { + $metaclass->clone_parent($self, $name, @_); + } + else { + $metaclass->create($self, $name, @_); + } + } + } } sub compute_all_applicable_attributes { @@ -351,7 +377,7 @@ Returns the name of the owner class. Gets (or sets) the list of superclasses of the owner class. -=head2 add_attribute Mouse::Meta::Attribute +=head2 add_attribute (Mouse::Meta::Attribute| name => spec) Begins keeping track of the existing L for the owner class.