added getTables()

This commit is contained in:
JT Smith 2009-10-22 15:03:38 -05:00
parent 96c8a7a47e
commit 95ecfc0adf
4 changed files with 75 additions and 16 deletions

View file

@ -22,6 +22,7 @@ use WebGUI::International;
our $VERSION = '0.0.1';
#-------------------------------------------------------------------
sub import {
my $class = shift;
if (! @_) {
@ -34,6 +35,7 @@ sub import {
$properties->[$i]{tableName} ||= $table;
}
}
$class->_install($super, 'getTables', $class->_gen_getTables());
# WebGUI::Definition->import uses caller, so avoid the extra entry in the call stack
my $next = $class->next::can;
@ -41,6 +43,21 @@ sub import {
goto $next;
}
#-------------------------------------------------------------------
sub _gen_getTables {
my $class = shift;
return sub {
my $self = shift;
my %tables;
foreach my $property ($self->getProperties) {
my $definition = $self->getProperty($property);
%tables{$definition->{tableName}} = 1;
}
return keys %tables;
};
}
#-------------------------------------------------------------------
sub _gen_getProperty {
my $class = shift;
my $superGetProperty = $class->next::method(@_);
@ -59,3 +76,40 @@ sub _gen_getProperty {
1;
__END__
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2009 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=head1 NAME
WebGUI::Definition::Asset
=head1 DESCRIPTION
Extends WebGUI::Definition with asset specific methods and convienences. It automatically inserts the tableName attribute as an element of each property if the property doesn't explicitly set it.
=head1 METHODS
The following methods are exposed through this class.
=head2 getProperty ( property )
Extends getProperty() method generated by WebGUI::Definition by automatically converting the label and hoverHelp elements into strings.
=head2 getTables ( )
Returns a list of the tables that this asset's properties are stored in.
=cut