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;
Internally, the metaclass for C<Point> has two
L<Moose::Meta::Attribute>. There are several methods for getting
meta-attributes out of a metaclass, one of which is
-C<get_attribute_map>. This method is called on the metaclass object.
-
-The C<get_attribute_map> method returns a hash reference that maps
-attribute names to their objects. In our case, C<get_attribute_map>
-might return something that looks like the following:
+C<get_attribute_list>. This method is called on the metaclass object.
- {
- x => $attr_object_for_x,
- y => $attr_object_for_y,
- }
+The C<get_attribute_list> method returns a list of attribute names. You can
+then use C<get_attribute> to get the L<Moose::Meta::Attribute> object itself.
-You can also get a single L<Moose::Meta::Attribute> with
-C<get_attribute('name')>. 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
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 ) {
label, we use it, otherwise we use the attribute name:
else {
- $dump .= $name;
+ $dump .= $attribute->name;
}
my $reader = $attribute->get_read_method;
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;
}
},
{
- name => 'attribute_map',
- attr_reader => 'get_attribute_map',
+ name => '_attribute_map',
+ attr_reader => '_attribute_map',
methods => {
get => 'get_attribute',
get_keys => 'get_attribute_list',
else {
$attr_desc = { @_ };
}
- $self->get_attribute_map->{$name} = $attr_desc;
+ $self->_attribute_map->{$name} = $attr_desc;
}
sub add_required_methods {
#
# 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
=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) >>