diff --git a/lib/WebGUI/Definition/Role/Object.pm b/lib/WebGUI/Definition/Role/Object.pm index 97aeb3551..de27eb776 100644 --- a/lib/WebGUI/Definition/Role/Object.pm +++ b/lib/WebGUI/Definition/Role/Object.pm @@ -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; } diff --git a/t/Definition.t b/t/Definition.t index c6b57960f..eeeee26c7 100644 --- a/t/Definition.t +++ b/t/Definition.t @@ -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', + ); + } {