Object::new - Pragma to implement constructor methods


NAME

Object::new - Pragma to implement constructor methods


VERSION 1.1

Included in ObjectTools 1.1 distribution.


SYNOPSIS

Class

    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 ) ] ;

Usage

    my $object = MyClass->new(digits => '123');


DESCRIPTION

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.


INSTALLATION

Prerequisites
    Perl version >= 5.6.1
CPAN
    perl -MCPAN -e 'install ObjectTools'
Standard installation
From the directory where this file is located, type:
    perl Makefile.PL
    make
    make test
    make install

OPTIONS

name
The name of the constructor method. If you omit this option the 'new' name will be used by default.

init
use this option if you want to call other method in your class to further initialize the object. You can group method by passing a reference to an array containing the methods names.

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 @_.


BUGS

None known, but the module is not completely tested.


CREDITS

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