From 059bd6761d4efe88f2feac19c955680302e1bc65 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 11 Dec 2009 11:56:16 -0800 Subject: [PATCH] Uniqueness check on attribute names in get_property_list. Add tests for that, and for get_attributes --- lib/WebGUI/Definition/Meta/Class.pm | 4 +++- t/Definition.t | 32 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/Definition/Meta/Class.pm b/lib/WebGUI/Definition/Meta/Class.pm index 5425804c9..648a00209 100644 --- a/lib/WebGUI/Definition/Meta/Class.pm +++ b/lib/WebGUI/Definition/Meta/Class.pm @@ -67,12 +67,14 @@ Returns an array reference of the names of all properties, in the order they wer =cut sub get_property_list { - my $self = shift; + my $self = shift; my @properties = (); + my %seen = (); CLASS: foreach my $className (reverse $self->linearized_isa()) { my $meta = $self->initialize($className); next CLASS unless $meta->isa('WebGUI::Definition::Meta::Class'); push @properties, + grep { ! $seen{$_}++ } # Uniqueness check 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 diff --git a/t/Definition.t b/t/Definition.t index e39536c33..966077dfc 100644 --- a/t/Definition.t +++ b/t/Definition.t @@ -115,6 +115,18 @@ my $called_getProperties; package main; + cmp_bag( + [ map {$_->name} WGT::Class::AlsoAsset->meta->get_attributes ], + [qw/property1 property2 property3/], + 'get_attributes returns attributes for my class' + ); + + cmp_bag( + [ map {$_->name} WGT::Class::Asset::Snippet->meta->get_attributes ], + [qw/property10 property11/], + '...even in a subclass' + ); + cmp_deeply( WGT::Class::Asset::Snippet->getProperties, [qw/property1 property2 property3 property10 property11/], @@ -122,3 +134,23 @@ my $called_getProperties; ); } + +{ + + package WGT::Class::Asset::NotherOne; + use WebGUI::Definition::Asset; + extends 'WGT::Class::AlsoAsset'; + + attribute tableName => 'snippet'; + property 'property10' => (); + property 'property1' => (); + + package main; + + cmp_deeply( + WGT::Class::Asset::NotherOne->getProperties, + [qw/property1 property2 property3 property10/], + 'checking inheritance of properties by name, insertion order with an overridden property' + ); + +}