NAME

Class::constr - Pragma to implement constructor methods

VERSION 1.4

Included in OOTools 1.4 distribution. The distribution includes:

  • Class::constr

    Pragma to implement constructor methods

  • Class::props

    Pragma to implement lvalue accessors with options

  • Class::group

    Pragma to implement group of properties accessors with options

  • Object::props

    Pragma to implement lvalue accessors with options

  • Object::group

    Pragma to implement group of properties accessors with options

SYNOPSIS

Class

package MyClass ;

# implement constructor without options
use Class::constr ;

# with options
use Class::constr { name      => 'new_object' ,
                    init      => [ qw( init1 init2 ) ] ,
                    no_strict => 1
                  } ;
                
# init1 and init2 will be called at run-time

Usage

# creates a new object and eventually validates
# the properties if any validation property option is set
my $object = MyClass->new(digits => '123');
                             

DESCRIPTION

This pragma easily implements lvalue constructor methods for your class. Use it with Class::props and Object::props to automatically validate the input passed with new(), or use the no_strict option to accept unknow properties as well.

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 OOTools'
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.

no_strict

With no_strict option set to a true value, the constructor method accepts and sets also unknown properties (i.e. not predeclared). You have to access the unknown properties without any accessor method. All the other options will work as expected. Without this option the constructor will croak if any property does not have an accessor method.

init

Use this option if you want to call other method in your class to further initialize the object. You can group methods by passing a reference to an array containing the method 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 @_.

SUPPORT and FEEDBACK

I would like to have just a line of feedback from everybody who tries or actually uses this module. PLEASE, write me any comment, suggestion or request. ;-)

More information at http://perl.4pro.net/?Class::constr.

AUTHOR and COPYRIGHT

© 2003 by Domizio Demichelis <dd@4pro.net>.

All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as perl itself.

CREDITS

Thanks to Juerd Waalboer (http://search.cpan.org/author/JUERD) that with its Attribute::Property inspired the creation of this distribution.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 167:

Non-ASCII character seen before =encoding in '©'. Assuming CP1252