rework WebGUI::Definition::Role::Object when passing sub refs for form property values.
This commit is contained in:
parent
b2b03b662c
commit
3b70d64b82
2 changed files with 21 additions and 11 deletions
|
|
@ -136,13 +136,13 @@ sub getFormProperties {
|
|||
my $self = shift;
|
||||
my $property = $self->meta->find_attribute_by_name(@_);
|
||||
my $form = $property->form;
|
||||
PROPERTY: while (my ($property_name, $property) = each %{ $form }) {
|
||||
next PROPERTY unless ref $property;
|
||||
if (($property_name eq 'label' || $property_name eq 'hoverHelp') and ref $property eq 'ARRAY') {
|
||||
$form->{$property_name} = WebGUI::International->new($self->session)->get(@{$property});
|
||||
PROPERTY: while (my ($property_name, $property_value) = each %{ $form }) {
|
||||
next PROPERTY unless ref $property_value;
|
||||
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_value});
|
||||
}
|
||||
elsif (ref $property eq 'CODE') {
|
||||
$form->{$property_name} = $self->$property($form, $property_name);
|
||||
elsif (ref $property_value eq 'CODE') {
|
||||
$form->{$property_name} = $self->$property_value($property, $property_name);
|
||||
}
|
||||
}
|
||||
return $form;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use lib "$FindBin::Bin/lib";
|
|||
|
||||
use WebGUI::Test;
|
||||
|
||||
use Test::More tests => 12;
|
||||
use Test::More tests => 15;
|
||||
use Test::Deep;
|
||||
use Test::Exception;
|
||||
|
||||
|
|
@ -104,8 +104,9 @@ my $called_getProperties;
|
|||
|
||||
aspect 'aspect1' => 'aspect1 value';
|
||||
property 'property1' => (
|
||||
label => ['webgui', 'WebGUI'],
|
||||
options => \&property1_options,
|
||||
label => ['webgui', 'WebGUI'],
|
||||
options => \&property1_options,
|
||||
named_url => \&named_url,
|
||||
);
|
||||
has session => (
|
||||
is => 'ro',
|
||||
|
|
@ -114,14 +115,23 @@ my $called_getProperties;
|
|||
sub property1_options {
|
||||
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});
|
||||
|
||||
::cmp_deeply(
|
||||
$object->getFormProperties('property1'),
|
||||
{
|
||||
label => 'WebGUI',
|
||||
options => { one => 1, two => 2, three => 3 },
|
||||
label => 'WebGUI',
|
||||
options => { one => 1, two => 2, three => 3 },
|
||||
named_url => 'property1',
|
||||
},
|
||||
'getFormProperties handles i18n and subroutines'
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue