NAME
PerlBean - Package to generate bean like Perl modules
SYNOPSIS
use strict;
use PerlBean;
use PerlBean::Attribute::Factory;
my $bean = PerlBean->new ();
my $factory = PerlBean::Attribute::Factory->new ();
my $attr = $factory->createAttribute ({
attribute_name => 'true',
short_description => 'something is true',
});
$bean->addAttribute ($attr);
use IO::File;
-d 'tmp' || mkdir ('tmp');
my $fh = IO::File->new ('> tmp/PerlBean.pl.out');
$bean->write ($fh);
ABSTRACT
Code generation for bean like Perl modules
DESCRIPTION
PerlBean generates bean like Perl packages. That is, it generates code with for a module with attributes (properties) and the attribute's access methods (set, push, pop, shift, unshift, has, get or is, depending on the type of attribute). The attribute base types are BOOLEAN, SINGLE and MULTI. BOOLEAN attributes may be set to 0 or 1. SINGLE attributes may contain any scalar. MULTI attributes contain a set of values (ordered/not ordered and unique/not unique).
The attribute insertion methods (setAttribute (), pushAttribute () and unshiftAttribute ()) accept PerlBean::Attribute objects. However, PerlBean::Attribute are best generated using PerlBean::Attribute::Factory. See the sample in the SYNOPSIS section.
Finaly, the actual bean code is written using the wite () method.
The generated code should be free of syntax errors. It's intended to be mixed with the application logic you intend to write yourself.
Background information: Of course the attribute code in PerlBean and PerlBean::Attribute are actually generated using this method.
CONSTRUCTOR
- new ([OPT_HASH_REF])
-
Creates a new
PerlBeanobject.OPT_HASH_REFis a hash reference used to pass initialization options. On error an exceptionError::Simpleis thrown.Options for
OPT_HASH_REFmay include:abstract-
Passed to "setAbstract ()".
attribute-
Passed to "setAttribute ()". Must be an
ARRAYreference. base-
Passed to "setBase ()". Must be an
ARRAYreference. collection-
Passed to "setCollection ()".
description-
Passed to "setDescription ()".
exception_class-
Passed to "setExceptionClass ()". Defaults to Error::Simple.
exported-
Passed to "setExported ()". Defaults to 0.
license-
Passed to "setLicense ()".
method-
Passed to "setMethod ()". Must be an
ARRAYreference. package-
Passed to "setPackage ()". Defaults to main.
short_description-
Passed to "setShortDescription ()". Defaults to NO DESCRIPTION AVAILABLE.
synopsis-
Passed to "setSynopsis ()".
METHODS
- write (FILEHANDLE)
-
Write the Perl class code to
FILEHANDLE.FILEHANDLEis anIO::Handleobject. On error an exceptionError::Simpleis thrown. - writeAllowIsaHash (FILEHANDLE)
-
Write the
%ALLOW_ISAhash toFILEHANDLE.FILEHANDLEis anIO::Handleobject. On error an exceptionError::Simpleis thrown. - writeAllowRefHash (FILEHANDLE)
-
Write the
%ALLOW_REFhash toFILEHANDLE.FILEHANDLEis anIO::Handleobject. On error an exceptionError::Simpleis thrown. - writeAllowRxHash (FILEHANDLE)
-
Write the
%ALLOW_RXhash toFILEHANDLE.FILEHANDLEis anIO::Handleobject. On error an exceptionError::Simpleis thrown. - writeAllowValueHash (FILEHANDLE)
-
Write the
%ALLOW_VALUEhash toFILEHANDLE.FILEHANDLEis anIO::Handleobject. On error an exceptionError::Simpleis thrown. - writeDefaultValueHash (FILEHANDLE)
-
Write the
%DEFAULT_VALUEhash toFILEHANDLE.FILEHANDLEis anIO::Handleobject. On error an exceptionError::Simpleis thrown. - setAbstract (VALUE)
-
Set the PerlBean' abstract.
VALUEis the value. On error an exceptionError::Simpleis thrown. - getAbstract ()
-
Returns the PerlBean' abstract.
- setAttribute ([VALUE ...])
-
Set the list of 'PerlBean::Attribute' objects absolutely using values. Each
VALUEis an object out of which the id is obtained through methodgetAttributeName (). The obtained key is used to store the value and may be used for deletion and to fetch the value. 0 or more values may be supplied. Multiple occurences of the same key yield in the last occuring key to be inserted and the rest to be ignored. Each key of the specified values is allowed to occur only once. On error an exceptionError::Simpleis thrown. - addAttribute ([VALUE ...])
-
Add additional values on the list of 'PerlBean::Attribute' objects. Each
VALUEis an object out of which the id is obtained through method(). The obtained key is used to store the value and may be used for deletion and to fetch the value. 0 or more values may be supplied. Multiple occurences of the same key yield in the last occuring key to be inserted and the rest to be ignored. Each key of the specified values is allowed to occur only once. On error an exceptionError::Simpleis thrown. - deleteAttribute (ARRAY)
-
Delete elements from the list of 'PerlBean::Attribute' objects. Returns the number of deleted elements. On error an exception
Error::Simpleis thrown. - existsAttribute (ARRAY)
-
Returns the count of items in
ARRAYthat are in the list of 'PerlBean::Attribute' objects. - keysAttribute ()
-
Returns an
ARRAYcontaining the keys of the list of 'PerlBean::Attribute' objects. - valuesAttribute ([KEY_ARRAY])
-
Returns an
ARRAYcontaining the values of the list of 'PerlBean::Attribute' objects. IfKEY_ARRAYcontains one or moreKEYs the values related to theKEYs are returned. If noKEYs specified all values are returned. - setBase (ARRAY)
-
Set the list of class names in use base absolutely.
ARRAYis the list value. Each element in the list is allowed to occur only once. Multiple occurences of the same element yield in the first occuring element to be inserted and the rest to be ignored. On error an exceptionError::Simpleis thrown. - pushBase (ARRAY)
-
Push additional values on the list of class names in use base.
ARRAYis the list value. The push may not yield to multiple identical elements in the list. Hence, multiple occurences of the same element are ignored. On error an exceptionError::Simpleis thrown. - popBase ()
-
Pop and return an element off the list of class names in use base. On error an exception
Error::Simpleis thrown. - shiftBase ()
-
Shift and return an element off the list of class names in use base. On error an exception
Error::Simpleis thrown. - unshiftBase (ARRAY)
-
Unshift additional values on the list of class names in use base.
ARRAYis the list value. The push may not yield to multiple identical elements in the list. Hence, multiple occurences of the same element are ignored. On error an exceptionError::Simpleis thrown. - existsBase (ARRAY)
-
Returns the count of items in
ARRAYthat are in the list of class names in use base. - getBase ()
-
Returns an
ARRAYcontaining the list of class names in use base.INDEX_ARRAYis an optional list of indexes which when specified causes only the indexed elements in the ordered list to be returned. If not specified, all elements are returned. - setCollection (VALUE)
-
Set class to throw when exception occurs.
VALUEis the value. On error an exceptionError::Simpleis thrown. - getCollection ()
-
Returns class to throw when exception occurs.
- setDescription (VALUE)
-
Set the PerlBean description.
VALUEis the value. On error an exceptionError::Simpleis thrown. - getDescription ()
-
Returns the PerlBean description.
- setExceptionClass (VALUE)
-
Set class to throw when exception occurs.
VALUEis the value. Default value at initialization isError::Simple.VALUEmay not beundef. On error an exceptionError::Simpleis thrown. - getExceptionClass ()
-
Returns class to throw when exception occurs.
- setExported (VALUE)
-
State that the PerlBean must contain code for exporter.
VALUEis the value. Default value at initialization is0. On error an exceptionError::Simpleis thrown. - isExported ()
-
Returns whether the PerlBean must contain code for exporter or not.
- setLicense (VALUE)
-
Set the software license for the PerlBean.
VALUEis the value. On error an exceptionError::Simpleis thrown. - getLicense ()
-
Returns the software license for the PerlBean.
- setMethod ([VALUE ...])
-
Set the list of 'PerlBean::Method' objects absolutely using values. Each
VALUEis an object out of which the id is obtained through methodgetMethodName (). The obtained key is used to store the value and may be used for deletion and to fetch the value. 0 or more values may be supplied. Multiple occurences of the same key yield in the last occuring key to be inserted and the rest to be ignored. Each key of the specified values is allowed to occur only once. On error an exceptionError::Simpleis thrown. - addMethod ([VALUE ...])
-
Add additional values on the list of 'PerlBean::Method' objects. Each
VALUEis an object out of which the id is obtained through method(). The obtained key is used to store the value and may be used for deletion and to fetch the value. 0 or more values may be supplied. Multiple occurences of the same key yield in the last occuring key to be inserted and the rest to be ignored. Each key of the specified values is allowed to occur only once. On error an exceptionError::Simpleis thrown. - deleteMethod (ARRAY)
-
Delete elements from the list of 'PerlBean::Method' objects. Returns the number of deleted elements. On error an exception
Error::Simpleis thrown. - existsMethod (ARRAY)
-
Returns the count of items in
ARRAYthat are in the list of 'PerlBean::Method' objects. - keysMethod ()
-
Returns an
ARRAYcontaining the keys of the list of 'PerlBean::Method' objects. - valuesMethod ([KEY_ARRAY])
-
Returns an
ARRAYcontaining the values of the list of 'PerlBean::Method' objects. IfKEY_ARRAYcontains one or moreKEYs the values related to theKEYs are returned. If noKEYs specified all values are returned. - setPackage (VALUE)
-
Set package name.
VALUEis the value. Default value at initialization ismain.VALUEmay not beundef. On error an exceptionError::Simpleis thrown. - getPackage ()
-
Returns package name.
- setShortDescription (VALUE)
-
Set the short PerlBean description.
VALUEis the value. Default value at initialization isNO DESCRIPTION AVAILABLE. On error an exceptionError::Simpleis thrown. - getShortDescription ()
-
Returns the short PerlBean description.
- setSynopsis (VALUE)
-
Set the synopsis for the PerlBean.
VALUEis the value. On error an exceptionError::Simpleis thrown. - getSynopsis ()
-
Returns the synopsis for the PerlBean.
SEE ALSO
PerlBean::Attribute, PerlBean::Attribute::Boolean, PerlBean::Attribute::Factory, PerlBean::Attribute::Multi, PerlBean::Attribute::Multi::Ordered, PerlBean::Attribute::Multi::Unique, PerlBean::Attribute::Multi::Unique::Associative, PerlBean::Attribute::Multi::Unique::Associative::MethodKey, PerlBean::Attribute::Multi::Unique::Ordered, PerlBean::Attribute::Single, PerlBean::Collection, PerlBean::Method
BUGS
None known (yet.)
HISTORY
First development: November 2002
AUTHOR
Vincenzo Zocca
COPYRIGHT
Copyright 2002, 2003 by Vincenzo Zocca
LICENSE
This file is part of the PerlBean module hierarchy for Perl by Vincenzo Zocca.
The PerlBean module hierarchy is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
The PerlBean module hierarchy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the PerlBean module hierarchy; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA