Force set to process properties in insertion order.
Note, we should look for a way to make this more efficient.
This commit is contained in:
parent
8837185bce
commit
030f6bccf0
2 changed files with 39 additions and 3 deletions
|
|
@ -86,9 +86,10 @@ is not an attribute of the object, then it is silently ignored.
|
|||
sub set {
|
||||
my $self = shift;
|
||||
my $properties = @_ % 2 ? shift : { @_ };
|
||||
KEY: for my $key ( keys %$properties ) {
|
||||
next KEY unless $self->meta->find_attribute_by_name($key);
|
||||
$self->$key($properties->{$key});
|
||||
my @orderedProperties = $self->getProperties;
|
||||
KEY: for my $property ( @orderedProperties ) {
|
||||
next KEY unless exists $properties->{$property};
|
||||
$self->$property($properties->{$property});
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,3 +61,38 @@ my $called_getProperties;
|
|||
|
||||
}
|
||||
|
||||
{
|
||||
package WGT::Class2;
|
||||
use WebGUI::Definition;
|
||||
|
||||
attribute 'attribute1' => 'attribute1 value';
|
||||
property 'property3' => ( label => 'label' );
|
||||
property 'property1' => ( label => 'label' );
|
||||
property 'property2' => ( label => 'label' );
|
||||
|
||||
my @set_order = ();
|
||||
|
||||
before 'property1' => sub {
|
||||
my $self = shift;
|
||||
push @set_order, '1';
|
||||
};
|
||||
|
||||
before 'property2' => sub {
|
||||
my $self = shift;
|
||||
push @set_order, '2';
|
||||
};
|
||||
|
||||
before 'property3' => sub {
|
||||
my $self = shift;
|
||||
push @set_order, '3';
|
||||
};
|
||||
|
||||
my $object = WGT::Class2->new();
|
||||
$object->set(property1 => 1, property2 => 0, property3 => 1);
|
||||
::cmp_deeply( [ @set_order ], [3,1,2], 'properties set in insertion order');
|
||||
|
||||
@set_order = ();
|
||||
$object->set(property2 => 1, property3 => 0, property1 => 1);
|
||||
::cmp_deeply( [ @set_order ], [3,1,2], '... and again');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue