From: Dave Rolsky Date: Thu, 1 Oct 2009 19:22:06 +0000 (-0500) Subject: deprecate get_attribute_map for roles, and remove it from the recipes X-Git-Tag: 0.93~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ce444596532d2ad02238b2cfce046773c27a89bc;p=gitmo%2FMoose.git deprecate get_attribute_map for roles, and remove it from the recipes --- diff --git a/Changes b/Changes index 8b31dc8..8229942 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,10 @@ Also see Moose::Manual::Delta for more details of, and workarounds for, noteworthy changes. + + * Moose::Meta::Role + - get_attribute_map is now deprecated (Dave Rolsky) + * replace two more eval { } calls with try { } (doy) 0.92 Tue, Sep 22, 2009 diff --git a/lib/Moose/Cookbook/Meta/Recipe2.pod b/lib/Moose/Cookbook/Meta/Recipe2.pod index 4c38c19..ad255a6 100644 --- a/lib/Moose/Cookbook/Meta/Recipe2.pod +++ b/lib/Moose/Cookbook/Meta/Recipe2.pod @@ -38,18 +38,19 @@ Moose::Cookbook::Meta::Recipe2 - A meta-attribute, attributes with labels sub dump { my $self = shift; + my $meta = $self->meta; + my $dump = ''; - my %attributes = %{ $self->meta->get_attribute_map }; - for my $name ( sort keys %attributes ) { - my $attribute = $attributes{$name}; + for my $attribute ( map { $meta->get_attribute($_) } + sort $meta->get_attribute_list ) { if ( $attribute->isa('MyApp::Meta::Attribute::Labeled') && $attribute->has_label ) { $dump .= $attribute->label; } else { - $dump .= $name; + $dump .= $attribute->name; } my $reader = $attribute->get_read_method; @@ -87,20 +88,12 @@ a concrete example. Internally, the metaclass for C has two L. There are several methods for getting meta-attributes out of a metaclass, one of which is -C. This method is called on the metaclass object. - -The C method returns a hash reference that maps -attribute names to their objects. In our case, C -might return something that looks like the following: +C. This method is called on the metaclass object. - { - x => $attr_object_for_x, - y => $attr_object_for_y, - } +The C method returns a list of attribute names. You can +then use C to get the L object itself. -You can also get a single L with -C. Once you have this meta-attribute object, -you can call methods on it like this: +Once you this meta-attribute object, you can call methods on it like this: print $point->meta->get_attribute('x')->type_constraint; => Int @@ -200,11 +193,12 @@ attribute's label if it has one. sub dump { my $self = shift; + my $meta = $self->meta; + my $dump = ''; - my %attributes = %{ $self->meta->get_attribute_map }; - for my $name ( sort keys %attributes ) { - my $attribute = $attributes{$name}; + for my $attribute ( map { $meta->get_attribute($_) } + sort $meta->get_attribute_list ) { if ( $attribute->isa('MyApp::Meta::Attribute::Labeled') && $attribute->has_label ) { @@ -221,7 +215,7 @@ defined. We could instead make the label C. If we have a label, we use it, otherwise we use the attribute name: else { - $dump .= $name; + $dump .= $attribute->name; } my $reader = $attribute->get_read_method; diff --git a/lib/Moose/Cookbook/Meta/Recipe3.pod b/lib/Moose/Cookbook/Meta/Recipe3.pod index fd2cc16..737906d 100644 --- a/lib/Moose/Cookbook/Meta/Recipe3.pod +++ b/lib/Moose/Cookbook/Meta/Recipe3.pod @@ -37,18 +37,19 @@ Moose::Cookbook::Meta::Recipe3 - Labels implemented via attribute traits sub dump { my $self = shift; + my $meta = $self->meta; + my $dump = ''; - my %attributes = %{ $self->meta->get_attribute_map }; - for my $name ( sort keys %attributes ) { - my $attribute = $attributes{$name}; + for my $attribute ( map { $meta->get_attribute($_) } + sort $meta->get_attribute_list ) { if ( $attribute->does('MyApp::Meta::Attribute::Trait::Labeled') && $attribute->has_label ) { $dump .= $attribute->label; } else { - $dump .= $name; + $dump .= $attribute->name; } my $reader = $attribute->get_read_method; diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 6af9f21..16a2161 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -71,8 +71,8 @@ foreach my $action ( } }, { - name => 'attribute_map', - attr_reader => 'get_attribute_map', + name => '_attribute_map', + attr_reader => '_attribute_map', methods => { get => 'get_attribute', get_keys => 'get_attribute_list', @@ -181,7 +181,7 @@ sub add_attribute { else { $attr_desc = { @_ }; } - $self->get_attribute_map->{$name} = $attr_desc; + $self->_attribute_map->{$name} = $attr_desc; } sub add_required_methods { @@ -566,7 +566,7 @@ sub create { # # has 'attribute_map' => ( # metaclass => 'Hash', -# reader => 'get_attribute_map', +# reader => '_attribute_map', # isa => 'HashRef[Str]', # provides => { # # 'set' => 'add_attribute' # has some special crap in it @@ -818,8 +818,6 @@ This is quite likely to change in the future. =item B<< $metarole->has_attribute($attribute_name) >> -=item B<< $metarole->get_attribute_map >> - =item B<< $metarole->get_attribute_list >> =item B<< $metarole->add_attribute($name, %options) >>