From ed752a25c324b754b3ae9e6c125b9c3aef7603c5 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 8 Jan 2010 09:04:27 -0800 Subject: [PATCH] Make WebGUI::Definition property methods work the same way that Moose attribute methods do. Specifically, get_property_list does not return property names from all classes. Add a new method to do that. Refactor and reuse lots of code. --- lib/WebGUI/Definition/Meta/Class.pm | 60 +++++++++++++++++++--------- lib/WebGUI/Definition/Role/Object.pm | 2 +- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/lib/WebGUI/Definition/Meta/Class.pm b/lib/WebGUI/Definition/Meta/Class.pm index 351f17765..ee95f3d8f 100644 --- a/lib/WebGUI/Definition/Meta/Class.pm +++ b/lib/WebGUI/Definition/Meta/Class.pm @@ -76,18 +76,35 @@ created in the Definition. sub get_all_properties { my $self = shift; my @properties = (); - CLASS: foreach my $meta ($self->get_all_class_metas) { - push @properties, - 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 - ; + foreach my $meta ($self->get_all_class_metas) { + push @properties, $meta->get_properties; } return @properties; } #------------------------------------------------------------------- +=head2 get_all_property_list ( ) + +Returns an array of the names of all Properties, in all classes, in the order they were +created in the Definition. + +=cut + +sub get_all_property_list { + my $self = shift; + my @names = (); + my %seen = (); + foreach my $meta ($self->get_all_class_metas) { + push @names, + grep { !$seen{$_}++ } + $meta->get_property_list; + } + return @names; +} + +#------------------------------------------------------------------- + =head2 get_attributes ( ) Returns an array of all attributes, but only for this class. This is the @@ -102,24 +119,31 @@ sub get_attributes { #------------------------------------------------------------------- +=head2 get_properties ( ) + +Returns an array of all properties, but only for this class. + +=cut + +sub get_properties { + my $self = shift; + return grep { $_->isa('WebGUI::Definition::Meta::Property') } $self->get_attributes; +} + +#------------------------------------------------------------------- + =head2 get_property_list ( ) -Returns an array of the names of all Properties, in all classes, in the -order they were created in the Definition. Duplicate names are filtered -out. +Returns an array of the names of all Properties, in this class, sorted by the order they +were added to the Definition. This guarantees repeatable, reliable handling of properties. =cut sub get_property_list { - my $self = shift; - my @properties = (); - my %seen = (); - push @properties, - grep { ! $seen{$_}++ } # Uniqueness check - map { $_->name } # Just the name - $self->get_all_properties - ; - return @properties; + my $self = shift; + return map { $_->name } + sort { $a->insertion_order <=> $b->insertion_order } # In insertion order + $self->get_properties } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Definition/Role/Object.pm b/lib/WebGUI/Definition/Role/Object.pm index 9bff40826..c3cd33b36 100644 --- a/lib/WebGUI/Definition/Role/Object.pm +++ b/lib/WebGUI/Definition/Role/Object.pm @@ -143,7 +143,7 @@ Returns a list of the names of all properties of the object, as set by the Defin sub getProperties { my $self = shift; - return $self->meta->get_property_list; + return $self->meta->get_all_property_list; } 1;