Object-InsideOut - Re: Default value

Posted on Thu Jan 25 15:09:08 2007 by jdhedden in response to 4148 (See the whole thread of 2)
Re: Default value
Using an array or hash reference as a default will probably not produce the result that you might expect:
my @foo :Field :Default({});
This does not result in a new empty hash reference being created for each new object. Rather, a single empty hash reference is created when the module is loaded, and then that reference is assigned to each newly created object. In other words, it is equivalent to:
my %bar = (); my @foo :Field :Default(\%bar);
To get the other result, assign a new empty hash reference using an :Init subroutine:
sub _init :Init { my ($self, $args) = @_; $foo[$$self] = {}; }
This explanation will be part of the POD in the next release. Thanks.
BTW, OIO 3.08 is the latest version.
Write a response