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->getAttributeName (), $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 ()".
package-
Passed to "setPackage ()". Defaults to main.
short_description-
Passed to "setShortDescription ()". Defaults to NO DESCRIPTION AVAILABLE.
synopsis-
Passed to "setSynopsis ()".
METHODS
- setAbstract (VALUE)
-
Set the PerlBean' abstract.
VALUEis the value. On error an exceptionError::Simpleis thrown. - getAbstract ()
-
Returns the PerlBean' abstract.
- setAttribute ([KEY, VALUE ...])
-
Set the list 'PerlBean::Attribute' objects absolutely using keys/values.
KEY, VALUEare key/value pairs. 0 or more of these pairs may be supplied. Each key in is allowed to occur only once. Multiple occurences of the same key yield in the last occuring key to be inserted and the rest to be ignored. On error an exceptionError::Simpleis thrown. - addAttribute ([KEY, VALUE ...])
-
Add additional keys/values on the list 'PerlBean::Attribute' objects.
KEY, VALUEare key/value pairs. The addition may not yield to multiple identical keys in the list. Hence, multiple occurences of the same key cause the last occurence to be inserted. On error an exceptionError::Simpleis thrown. - deleteAttribute (ARRAY)
-
Delete elements from the list '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 'PerlBean::Attribute' objects. - keysAttribute ()
-
Returns an
ARRAYcontaining the keys of the list 'PerlBean::Attribute' objects. - valuesAttribute ([KEY_ARRAY])
-
Returns an
ARRAYcontaining the values of the list '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.
- 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.
- write (FILEHANDLE)
-
Write the Perl class code to
FILEHANDLE.FILEHANDLEis anIO::Handleobject. On error an exceptionError::Simpleis thrown. - 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::Ordered, PerlBean::Attribute::Single, PerlBean::Collection
BUGS
None known (yet.)
HISTORY
First development: November 2002
AUTHOR
Vincenzo Zocca
COPYRIGHT
Copyright 2002 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