add get_tables, and refactor out get_all_properties from get_property_list
This commit is contained in:
parent
5b5d4783d0
commit
c93bdc7950
2 changed files with 77 additions and 12 deletions
|
|
@ -46,6 +46,30 @@ These methods are available from this class:
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get_all_properties ( )
|
||||
|
||||
Returns an array of all Properties, in all classes, in the
|
||||
order they were created in the Definition.
|
||||
|
||||
=cut
|
||||
|
||||
sub get_all_properties {
|
||||
my $self = shift;
|
||||
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,
|
||||
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;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get_attributes ( )
|
||||
|
||||
Returns an array of all attributes, but only for this class. This
|
||||
|
|
@ -62,7 +86,9 @@ sub get_attributes {
|
|||
|
||||
=head2 get_property_list ( )
|
||||
|
||||
Returns an array reference of the names of all properties, in the order they were created in the Definition.
|
||||
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.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -70,17 +96,32 @@ sub get_property_list {
|
|||
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
|
||||
$meta->get_attributes # All attributes
|
||||
;
|
||||
}
|
||||
push @properties,
|
||||
grep { ! $seen{$_}++ } # Uniqueness check
|
||||
map { $_->name } # Just the name
|
||||
$self->get_all_properties
|
||||
;
|
||||
return @properties;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get_tables ( )
|
||||
|
||||
Returns an array of the names of all tables in every class used by
|
||||
this Class.
|
||||
|
||||
=cut
|
||||
|
||||
sub get_tables {
|
||||
my $self = shift;
|
||||
my @properties = ();
|
||||
my %seen = ();
|
||||
push @properties,
|
||||
grep { ! $seen{$_}++ }
|
||||
map { $_->tableName }
|
||||
$self->get_all_properties
|
||||
;
|
||||
return @properties;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@ my $called_getProperties;
|
|||
# can retreive property metadata
|
||||
::is +__PACKAGE__->getProperty('property1')->form->{'arbitrary_key'}, 'arbitrary_value', 'arbitrary keys mapped into the form attribute';
|
||||
|
||||
# can retreive property metadata
|
||||
::is +__PACKAGE__->getProperty('property1')->form->{'arbitrary_key'}, 'arbitrary_value', 'arbitrary keys mapped into the form attribute';
|
||||
|
||||
# can retreive property metadata
|
||||
::isa_ok +__PACKAGE__->getProperty('property1'), 'WebGUI::Definition::Meta::Property';
|
||||
|
||||
::cmp_deeply(
|
||||
[ +__PACKAGE__->getProperties ],
|
||||
|
|
@ -66,6 +71,7 @@ my $called_getProperties;
|
|||
}
|
||||
|
||||
::is +__PACKAGE__->meta->get_attribute('property1')->tableName, 'asset', 'tableName copied from attribute into property';
|
||||
::isa_ok +__PACKAGE__->getProperty('property1'), 'WebGUI::Definition::Meta::Property::Asset';
|
||||
|
||||
::can_ok +__PACKAGE__, 'update';
|
||||
|
||||
|
|
@ -86,12 +92,24 @@ my $called_getProperties;
|
|||
'->meta->get_property_list returns properties as a list in insertion order'
|
||||
);
|
||||
|
||||
::cmp_deeply(
|
||||
[ $object->meta->get_all_properties ],
|
||||
::array_each(::isa('WebGUI::Definition::Meta::Property::Asset')),
|
||||
'->meta->get_all_properties returns a list of Properties'
|
||||
);
|
||||
|
||||
::cmp_deeply(
|
||||
[$object->getProperties ],
|
||||
[qw/property2 property1/],
|
||||
'getProperties is an alias for ->meta->get_property_list'
|
||||
);
|
||||
|
||||
::cmp_deeply(
|
||||
[$object->meta->get_tables ],
|
||||
[qw/asset/],
|
||||
'get_tables returns a list of all tables used by this class'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -152,4 +170,10 @@ my $called_getProperties;
|
|||
'checking inheritance of properties by name, insertion order with an overridden property'
|
||||
);
|
||||
|
||||
cmp_deeply(
|
||||
[WGT::Class::Asset::NotherOne->meta->get_tables],
|
||||
[qw/asset snippet/],
|
||||
'get_tables returns both tables'
|
||||
);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue