allow getFormProperties to be called as a class method
This commit is contained in:
parent
3bb4754487
commit
03f64cbf1a
2 changed files with 20 additions and 1 deletions
|
|
@ -150,13 +150,21 @@ The name of the property to return.
|
||||||
|
|
||||||
sub getFormProperties {
|
sub getFormProperties {
|
||||||
my $self = shift;
|
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 $property = $self->meta->find_attribute_by_name(@_);
|
||||||
my $form = $property->form;
|
my $form = $property->form;
|
||||||
PROPERTY: while (my ($property_name, $property_value) = each %{ $form }) {
|
PROPERTY: while (my ($property_name, $property_value) = each %{ $form }) {
|
||||||
next PROPERTY unless ref $property_value;
|
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') {
|
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 ($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) {
|
if (@arguments) {
|
||||||
$text = sprintf $text, @arguments;
|
$text = sprintf $text, @arguments;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,17 @@ my $session = WebGUI::Test->session;
|
||||||
'getFormProperties handles i18n and subroutines'
|
'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',
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue