|
Object::new - Pragma to implement constructor methods |
Object::new - Pragma to implement constructor methods
Included in ObjectTools 1.1 distribution.
package MyClass ;
# implement constructor without options
use Object::new ;
# this will be called by default if defined
sub _init
{
my ($s, @args) = @_
....
}
# with options
use Object::new name => 'new_object'
init => [ qw( init1 init2 ) ] ;
my $object = MyClass->new(digits => '123');
This pragma easily implements lvalue constructor methods for your class.
You can completely avoid to write the constructor by just using it and eventually declaring the name and the init methods to call.
Perl version >= 5.6.1
perl -MCPAN -e 'install ObjectTools'
perl Makefile.PL
make
make test
make install
After the assignation and validation of the properties, the initialization methods in the init option will be called. Each init method will receive the blessed object passed in $_[0] and the other (original) parameter in the remaining @_.
None known, but the module is not completely tested.
Thanks to Juerd Waalboer (http://search.cpan.org/author/JUERD) that with its Attribute::Property inspired the creation of this distribution.
|
Object::new - Pragma to implement constructor methods |