allow getFormProperties to be called as a class method

This commit is contained in:
Doug Bell 2011-01-31 20:35:25 -06:00
parent 3bb4754487
commit 03f64cbf1a
2 changed files with 20 additions and 1 deletions

View file

@ -150,13 +150,21 @@ The name of the property to return.
sub getFormProperties {
my $self = shift;
# If called as a class method, get a session
# If called as an object method, session is set when first needed below
my $session;
if ( !ref $self ) {
$session = shift;
}
my $property = $self->meta->find_attribute_by_name(@_);
my $form = $property->form;
PROPERTY: while (my ($property_name, $property_value) = each %{ $form }) {
next PROPERTY unless ref $property_value;
if (($property_name eq 'label' || $property_name eq 'hoverHelp' || $property_name eq 'subtext') and ref $property_value eq 'ARRAY') {
my ($label, $namespace, @arguments) = @{ $property_value };
my $text = WebGUI::International->new($self->session)->get($label, $namespace);
my $text = WebGUI::International->new($session ||= $self->session)->get($label, $namespace);
if (@arguments) {
$text = sprintf $text, @arguments;
}

View file

@ -143,6 +143,17 @@ my $session = WebGUI::Test->session;
'getFormProperties handles i18n and subroutines'
);
::cmp_deeply(
__PACKAGE__->getFormProperties($object->session,'property1'),
{
label => 'WebGUI',
hoverHelp => 'webgui help extra',
options => { one => 1, two => 2, three => 3 },
named_url => 'property1',
},
'getFormProperties called as class method',
);
}
{