diff --git a/lib/WebGUI/Definition/Meta/Class.pm b/lib/WebGUI/Definition/Meta/Class.pm index 8ea4460ac..5425804c9 100644 --- a/lib/WebGUI/Definition/Meta/Class.pm +++ b/lib/WebGUI/Definition/Meta/Class.pm @@ -46,6 +46,20 @@ These methods are available from this class: #------------------------------------------------------------------- +=head2 get_attributes ( ) + +Returns an array of all attributes, but only for this class. This +is the API-safe way of doing $self->_attribute_map; + +=cut + +sub get_attributes { + my $self = shift; + return map { $self->find_attribute_by_name($_) } $self->get_attribute_list; +} + +#------------------------------------------------------------------- + =head2 get_property_list ( ) Returns an array reference of the names of all properties, in the order they were created in the Definition. @@ -54,11 +68,17 @@ Returns an array reference of the names of all properties, in the order they wer sub get_property_list { my $self = shift; - my @properties = - map { $_->name } - sort { $a->insertion_order <=> $b->insertion_order } - grep { $_->isa('WebGUI::Definition::Meta::Property') } - $self->get_all_attributes; + my @properties = (); + CLASS: foreach my $className (reverse $self->linearized_isa()) { + my $meta = $self->initialize($className); + next CLASS unless $meta->isa('WebGUI::Definition::Meta::Class'); + push @properties, + map { $_->name } # Just the name + sort { $a->insertion_order <=> $b->insertion_order } # In insertion order + grep { $_->isa('WebGUI::Definition::Meta::Property') } # that are Meta::Properties + $meta->get_attributes # All attributes + ; + } return \@properties; } diff --git a/t/Definition.t b/t/Definition.t index e73d2cf07..e39536c33 100644 --- a/t/Definition.t +++ b/t/Definition.t @@ -44,6 +44,7 @@ my $called_getProperties; # can retreive property metadata ::is +__PACKAGE__->getProperty('property1')->form->{'arbitrary_key'}, 'arbitrary_value', 'arbitrary keys mapped into the form attribute'; + ::cmp_deeply( +__PACKAGE__->getProperties, [qw/property1 property2/], @@ -94,4 +95,30 @@ my $called_getProperties; } +{ + package WGT::Class::AlsoAsset; + use WebGUI::Definition::Asset; + + attribute tableName => 'asset'; + property 'property1' => (); + property 'property2' => (); + property 'property3' => (); + + package WGT::Class::Asset::Snippet; + use WebGUI::Definition::Asset; + extends 'WGT::Class::AlsoAsset'; + + attribute tableName => 'snippet'; + property 'property10' => (); + property 'property11' => (); + + package main; + + cmp_deeply( + WGT::Class::Asset::Snippet->getProperties, + [qw/property1 property2 property3 property10 property11/], + 'checking inheritance of properties by name, insertion order' + ); + +}