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
PerlBean
object.OPT_HASH_REF
is a hash reference used to pass initialization options. On error an exceptionError::Simple
is thrown.Options for
OPT_HASH_REF
may include:abstract
-
Passed to "setAbstract ()".
attribute
-
Passed to "setAttribute ()". Must be an
ARRAY
reference. base
-
Passed to "setBase ()". Must be an
ARRAY
reference. 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.
VALUE
is the value. On error an exceptionError::Simple
is thrown. - getAbstract ()
-
Returns the PerlBean' abstract.
- setAttribute ([KEY, VALUE ...])
-
Set the list 'PerlBean::Attribute' objects absolutely using keys/values.
KEY, VALUE
are 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::Simple
is thrown. - addAttribute ([KEY, VALUE ...])
-
Add additional keys/values on the list 'PerlBean::Attribute' objects.
KEY, VALUE
are 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::Simple
is thrown. - deleteAttribute (ARRAY)
-
Delete elements from the list 'PerlBean::Attribute' objects. Returns the number of deleted elements. On error an exception
Error::Simple
is thrown. - existsAttribute (ARRAY)
-
Returns the count of items in
ARRAY
that are in the list 'PerlBean::Attribute' objects. - keysAttribute ()
-
Returns an
ARRAY
containing the keys of the list 'PerlBean::Attribute' objects. - valuesAttribute ([KEY_ARRAY])
-
Returns an
ARRAY
containing the values of the list 'PerlBean::Attribute' objects. IfKEY_ARRAY
contains one or moreKEY
s the values related to theKEY
s are returned. If noKEY
s specified all values are returned. - setBase (ARRAY)
-
Set the list of class names in use base absolutely.
ARRAY
is 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::Simple
is thrown. - pushBase (ARRAY)
-
Push additional values on the list of class names in use base.
ARRAY
is 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::Simple
is thrown. - popBase ()
-
Pop and return an element off the list of class names in use base. On error an exception
Error::Simple
is thrown. - shiftBase ()
-
Shift and return an element off the list of class names in use base. On error an exception
Error::Simple
is thrown. - unshiftBase (ARRAY)
-
Unshift additional values on the list of class names in use base.
ARRAY
is 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::Simple
is thrown. - existsBase (ARRAY)
-
Returns the count of items in
ARRAY
that are in the list of class names in use base. - getBase ()
-
Returns an
ARRAY
containing the list of class names in use base.INDEX_ARRAY
is 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.
VALUE
is the value. On error an exceptionError::Simple
is thrown. - getCollection ()
-
Returns class to throw when exception occurs.
- setDescription (VALUE)
-
Set the PerlBean description.
VALUE
is the value. On error an exceptionError::Simple
is thrown. - getDescription ()
-
Returns the PerlBean description.
- setExceptionClass (VALUE)
-
Set class to throw when exception occurs.
VALUE
is the value. Default value at initialization isError::Simple
.VALUE
may not beundef
. On error an exceptionError::Simple
is thrown. - getExceptionClass ()
-
Returns class to throw when exception occurs.
- setExported (VALUE)
-
State that the PerlBean must contain code for exporter.
VALUE
is the value. Default value at initialization is0
. On error an exceptionError::Simple
is thrown. - isExported ()
-
Returns whether the PerlBean must contain code for exporter or not.
- setLicense (VALUE)
-
Set the software license for the PerlBean.
VALUE
is the value. On error an exceptionError::Simple
is thrown. - getLicense ()
-
Returns the software license for the PerlBean.
- setPackage (VALUE)
-
Set package name.
VALUE
is the value. Default value at initialization ismain
.VALUE
may not beundef
. On error an exceptionError::Simple
is thrown. - getPackage ()
-
Returns package name.
- setShortDescription (VALUE)
-
Set the short PerlBean description.
VALUE
is the value. Default value at initialization isNO DESCRIPTION AVAILABLE
. On error an exceptionError::Simple
is thrown. - getShortDescription ()
-
Returns the short PerlBean description.
- write (FILEHANDLE)
-
Write the Perl class code to
FILEHANDLE
.FILEHANDLE
is anIO::Handle
object. On error an exceptionError::Simple
is thrown. - setSynopsis (VALUE)
-
Set the synopsis for the PerlBean.
VALUE
is the value. On error an exceptionError::Simple
is 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