Thread

Posted on Thu Nov 17 17:35:05 2005 by earl
Migrating from Class::Std
Is the :Init subroutine required? In a class that uses Class::Std, if the BUILD subroutine does not initialize a field, then the implicit new constructor will try to do a no-brainer initialization. When converting a module that uses Class::Std, I was getting an error message about Unhandled arguments. Adding an :Init subroutine made the problem go away. Does the Object::InsideOut module have a way to to simplify the following so the :Init subroutine is not needed?
my @myfield :Field; my %int_args :InitArgs = { 'myfield' => { 'Mandatory' => 1 } }; sub BUILD :Init { my ($self, $arg_ref) = @_; $self->set(\@myfield, $arg_ref=>{'myfield'} }
Someone who was indoctrinated with Class::Std may assume that functionality is there. It seems like the program could help me reduce trivial and redundant code. Thanks.
Direct Responses: 1339 | Write a response
Posted on Thu Nov 17 20:29:33 2005 by jdhedden in response to 1336
Re: Migrating from Class::Std
:InitArgs can be automatically placed into object fields by tying them together using :InitArg's Field designator:
my @myfield :Field; my %init_args :InitArgs = ( 'myfield' => { 'Field' => \@myfield, 'Mandatory' => 1 } );
If all the :InitArgs are handled in this manner, then the :Init subroutine is optional.
Write a response