rework WebGUI::Definition::Role::Object when passing sub refs for form property values.

This commit is contained in:
Colin Kuskie 2010-02-09 19:28:45 -08:00
parent b2b03b662c
commit 3b70d64b82
2 changed files with 21 additions and 11 deletions

View file

@ -136,13 +136,13 @@ sub getFormProperties {
my $self = shift; my $self = 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) = each %{ $form }) { PROPERTY: while (my ($property_name, $property_value) = each %{ $form }) {
next PROPERTY unless ref $property; next PROPERTY unless ref $property_value;
if (($property_name eq 'label' || $property_name eq 'hoverHelp') and ref $property eq 'ARRAY') { if (($property_name eq 'label' || $property_name eq 'hoverHelp') and ref $property_value eq 'ARRAY') {
$form->{$property_name} = WebGUI::International->new($self->session)->get(@{$property}); $form->{$property_name} = WebGUI::International->new($self->session)->get(@{$property_value});
} }
elsif (ref $property eq 'CODE') { elsif (ref $property_value eq 'CODE') {
$form->{$property_name} = $self->$property($form, $property_name); $form->{$property_name} = $self->$property_value($property, $property_name);
} }
} }
return $form; return $form;

View file

@ -16,7 +16,7 @@ use lib "$FindBin::Bin/lib";
use WebGUI::Test; use WebGUI::Test;
use Test::More tests => 12; use Test::More tests => 15;
use Test::Deep; use Test::Deep;
use Test::Exception; use Test::Exception;
@ -104,8 +104,9 @@ my $called_getProperties;
aspect 'aspect1' => 'aspect1 value'; aspect 'aspect1' => 'aspect1 value';
property 'property1' => ( property 'property1' => (
label => ['webgui', 'WebGUI'], label => ['webgui', 'WebGUI'],
options => \&property1_options, options => \&property1_options,
named_url => \&named_url,
); );
has session => ( has session => (
is => 'ro', is => 'ro',
@ -114,14 +115,23 @@ my $called_getProperties;
sub property1_options { sub property1_options {
return { one => 1, two => 2, three => 3 }; return { one => 1, two => 2, three => 3 };
} }
sub named_url {
my ($self, $property, $property_name) = @_;
::note "Checking arguments passed to subroutine for defining a form property";
::isa_ok($self, 'WGT::Class3');
::isa_ok($property, 'WebGUI::Definition::Meta::Property');
::is($property_name, 'named_url', 'form property name sent');
return $property->name;
}
my $object = WGT::Class3->new({session => $session}); my $object = WGT::Class3->new({session => $session});
::cmp_deeply( ::cmp_deeply(
$object->getFormProperties('property1'), $object->getFormProperties('property1'),
{ {
label => 'WebGUI', label => 'WebGUI',
options => { one => 1, two => 2, three => 3 }, options => { one => 1, two => 2, three => 3 },
named_url => 'property1',
}, },
'getFormProperties handles i18n and subroutines' 'getFormProperties handles i18n and subroutines'
); );