Thread

Posted on Mon Jan 30 18:31:51 2006 by berkan
Runtime behaviour for the 'Default' argument
Hi,

Thanks for the brilliant module -- it really makes development an order of magnitude easier.

I have one little request: I'm curious how easy it would be to have the Default field of the parameter initialisation arguments to determine the default values not when the relevant module is loaded but when an object is created. In other words, to have the Default argument behave more like the Type argument which allows the developer to specify an anonymous subroutine / subroutine reference for runtime checking.

Cheers,

Berkan

Direct Responses: 1726 | Write a response
Posted on Tue Jan 31 15:24:57 2006 by jdhedden in response to 1720
Re: Runtime behaviour for the 'Default' argument
There is a crucial difference between 'Type' and 'Default': 'Type' is a control, but 'Default' is a value. Changing 'Default' to behave as a control by having it process a code reference precludes its use for providing a code reference as a default value. Programmatic determination of a 'default' value needs to be done in the ':Init' subroutine:
package My::Class; { use Object::InsideOut; my @data :Field; my %init_args :InitArgs = ( 'DATA' => { 'Field' => \@data, }, ) sub init :Init { my ($self, $args) = @_; # Check if data exists if (! exists($data[$$self])) { # Provide 'default' value } } }
Write a response