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.
This commit is contained in:
Colin Kuskie 2010-01-08 09:04:27 -08:00
parent 49992dddb9
commit ed752a25c3
2 changed files with 43 additions and 19 deletions

View file

@ -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
}
#-------------------------------------------------------------------

View file

@ -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;