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->create_attribute( {
attribute_name => 'true',
short_description => 'something is true',
} );
$bean->add_attribute($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 (set_attribute()
, push_attribute()
and unshift_attribute()) 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 write()
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 set_abstract().
attribute
-
Passed to set_attribute(). Must be an
ARRAY
reference. autoloaded
-
Passed to set_autoloaded(). Defaults to 1.
base
-
Passed to set_base(). Must be an
ARRAY
reference. collection
-
Passed to set_collection().
dependency
-
Passed to set_dependency(). Must be an
ARRAY
reference. Defaults to a set ofPerlBean::Dependency
objects that yields to:use strict; use warnings; use Error qw(:try);
description
-
Passed to set_description().
exception_class
-
Passed to set_exception_class(). Defaults to 'Error::Simple'.
export_tag_description
-
Passed to set_export_tag_description(). Must be an
ARRAY
reference. license
-
Passed to set_license().
method
-
Passed to set_method(). Must be an
ARRAY
reference. package
-
Passed to set_package(). Defaults to 'main'.
short_description
-
Passed to set_short_description(). Defaults to 'NO DESCRIPTION AVAILABLE'.
singleton
-
Passed to set_singleton(). Defaults to 0.
symbol
-
Passed to set_symbol(). Must be an
ARRAY
reference. synopsis
-
Passed to set_synopsis().
use_perl_version
-
Passed to set_use_perl_version(). Defaults to $].
METHODS
- write(FILEHANDLE)
-
Write the Perl class code to
FILEHANDLE
.FILEHANDLE
is anIO::Handle
object. On error an exceptionError::Simple
is thrown. - set_abstract(VALUE)
-
Set the PerlBean's abstract (a one line description of the module).
VALUE
is the value. On error an exceptionError::Simple
is thrown. - get_abstract()
-
Returns the PerlBean's abstract (a one line description of the module).
- set_attribute( [ VALUE ... ] )
-
Set the list of 'PerlBean::Attribute' objects absolutely using values. Each
VALUE
is an object out of which the id is obtained through methodget_attribute_name()
. 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::Simple
is thrown. - add_attribute( [ VALUE ... ] )
-
Add additional values on the list of 'PerlBean::Attribute' objects. Each
VALUE
is an object out of which the id is obtained through methodget_attribute_name()
. 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::Simple
is thrown. - delete_attribute(ARRAY)
-
Delete elements from the list of 'PerlBean::Attribute' objects. Returns the number of deleted elements. On error an exception
Error::Simple
is thrown. - exists_attribute(ARRAY)
-
Returns the count of items in
ARRAY
that are in the list of 'PerlBean::Attribute' objects. - keys_attribute()
-
Returns an
ARRAY
containing the keys of the list of 'PerlBean::Attribute' objects. - values_attribute( [ KEY_ARRAY ] )
-
Returns an
ARRAY
containing the values of the list of '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. - set_autoloaded(VALUE)
-
State that the methods in the PerlBean are autoloaded.
VALUE
is the value. Default value at initialization is1
. On error an exceptionError::Simple
is thrown. - is_autoloaded()
-
Returns whether the methods in the PerlBean are autoloaded or not.
- set_base(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. - push_base(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. - pop_base()
-
Pop and return an element off the list of class names in use base. On error an exception
Error::Simple
is thrown. - shift_base()
-
Shift and return an element off the list of class names in use base. On error an exception
Error::Simple
is thrown. - unshift_base(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. - exists_base(ARRAY)
-
Returns the count of items in
ARRAY
that are in the list of class names in use base. - get_base()
-
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. - set_collection(VALUE)
-
Set class to throw when exception occurs.
VALUE
is the value. On error an exceptionError::Simple
is thrown. - get_collection()
-
Returns class to throw when exception occurs.
- set_dependency( [ VALUE ... ] )
-
Set the list of 'PerlBean::Dependency' objects absolutely using values. Each
VALUE
is an object out of which the id is obtained through methodget_dependency_name()
. 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::Simple
is thrown. Defaults value at initialization is a set ofPerlBean::Dependency
objects that yields to:use strict; use warnings; use Error qw(:try);
- add_dependency( [ VALUE ... ] )
-
Add additional values on the list of 'PerlBean::Dependency' objects. Each
VALUE
is an object out of which the id is obtained through methodget_dependency_name()
. 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::Simple
is thrown. - delete_dependency(ARRAY)
-
Delete elements from the list of 'PerlBean::Dependency' objects. Returns the number of deleted elements. On error an exception
Error::Simple
is thrown. - exists_dependency(ARRAY)
-
Returns the count of items in
ARRAY
that are in the list of 'PerlBean::Dependency' objects. - keys_dependency()
-
Returns an
ARRAY
containing the keys of the list of 'PerlBean::Dependency' objects. - values_dependency( [ KEY_ARRAY ] )
-
Returns an
ARRAY
containing the values of the list of 'PerlBean::Dependency' objects. IfKEY_ARRAY
contains one or moreKEY
s the values related to theKEY
s are returned. If noKEY
s specified all values are returned. - set_description(VALUE)
-
Set the PerlBean description.
VALUE
is the value. On error an exceptionError::Simple
is thrown. - get_description()
-
Returns the PerlBean description.
- set_exception_class(VALUE)
-
Set class to throw when exception occurs.
VALUE
is the value. Default value at initialization is'Error::Simple'
.VALUE
may not beundef
. On error an exceptionError::Simple
is thrown. - get_exception_class()
-
Returns class to throw when exception occurs.
- set_export_tag_description( [ VALUE ... ] )
-
Set the list of 'PerlBean::Described::ExportTag' objects absolutely using values. Each
VALUE
is an object out of which the id is obtained through methodget_export_tag_name()
. 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::Simple
is thrown. - add_export_tag_description( [ VALUE ... ] )
-
Add additional values on the list of 'PerlBean::Described::ExportTag' objects. Each
VALUE
is an object out of which the id is obtained through methodget_export_tag_name()
. 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::Simple
is thrown. - delete_export_tag_description(ARRAY)
-
Delete elements from the list of 'PerlBean::Described::ExportTag' objects. Returns the number of deleted elements. On error an exception
Error::Simple
is thrown. - exists_export_tag_description(ARRAY)
-
Returns the count of items in
ARRAY
that are in the list of 'PerlBean::Described::ExportTag' objects. - keys_export_tag_description()
-
Returns an
ARRAY
containing the keys of the list of 'PerlBean::Described::ExportTag' objects. - values_export_tag_description( [ KEY_ARRAY ] )
-
Returns an
ARRAY
containing the values of the list of 'PerlBean::Described::ExportTag' objects. IfKEY_ARRAY
contains one or moreKEY
s the values related to theKEY
s are returned. If noKEY
s specified all values are returned. - set_license(VALUE)
-
Set the software license for the PerlBean.
VALUE
is the value. On error an exceptionError::Simple
is thrown. - get_license()
-
Returns the software license for the PerlBean.
- set_method( [ VALUE ... ] )
-
Set the list of 'PerlBean::Method' objects absolutely using values. Each
VALUE
is an object out of which the id is obtained through methodget_method_name()
. 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::Simple
is thrown. - add_method( [ VALUE ... ] )
-
Add additional values on the list of 'PerlBean::Method' objects. Each
VALUE
is an object out of which the id is obtained through methodget_method_name()
. 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::Simple
is thrown. - delete_method(ARRAY)
-
Delete elements from the list of 'PerlBean::Method' objects. Returns the number of deleted elements. On error an exception
Error::Simple
is thrown. - exists_method(ARRAY)
-
Returns the count of items in
ARRAY
that are in the list of 'PerlBean::Method' objects. - keys_method()
-
Returns an
ARRAY
containing the keys of the list of 'PerlBean::Method' objects. - values_method( [ KEY_ARRAY ] )
-
Returns an
ARRAY
containing the values of the list of 'PerlBean::Method' objects. IfKEY_ARRAY
contains one or moreKEY
s the values related to theKEY
s are returned. If noKEY
s specified all values are returned. - set_package(VALUE)
-
Set package name.
VALUE
is the value. Default value at initialization is'main'
.VALUE
may not beundef
. On error an exceptionError::Simple
is thrown. - get_package()
-
Returns package name.
- set_short_description(VALUE)
-
Set the short PerlBean description.
VALUE
is the value. Default value at initialization is'NO DESCRIPTION AVAILABLE'
. On error an exceptionError::Simple
is thrown. - get_short_description()
-
Returns the short PerlBean description.
- set_singleton(VALUE)
-
State that the package is a singleton and an
instance()
method is implemented.VALUE
is the value. Default value at initialization is0
. On error an exceptionError::Simple
is thrown. - is_singleton()
-
Returns whether the package is a singleton and an
instance()
method is implemented or not. - set_symbol( [ VALUE ... ] )
-
Set the list of 'PerlBean::Symbol' objects absolutely using values. Each
VALUE
is an object out of which the id is obtained through methodget_symbol_name()
. 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::Simple
is thrown. - add_symbol( [ VALUE ... ] )
-
Add additional values on the list of 'PerlBean::Symbol' objects. Each
VALUE
is an object out of which the id is obtained through methodget_symbol_name()
. 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::Simple
is thrown. - delete_symbol(ARRAY)
-
Delete elements from the list of 'PerlBean::Symbol' objects. Returns the number of deleted elements. On error an exception
Error::Simple
is thrown. - exists_symbol(ARRAY)
-
Returns the count of items in
ARRAY
that are in the list of 'PerlBean::Symbol' objects. - keys_symbol()
-
Returns an
ARRAY
containing the keys of the list of 'PerlBean::Symbol' objects. - values_symbol( [ KEY_ARRAY ] )
-
Returns an
ARRAY
containing the values of the list of 'PerlBean::Symbol' objects. IfKEY_ARRAY
contains one or moreKEY
s the values related to theKEY
s are returned. If noKEY
s specified all values are returned. - set_synopsis(VALUE)
-
Set the synopsis for the PerlBean.
VALUE
is the value. On error an exceptionError::Simple
is thrown. - get_synopsis()
-
Returns the synopsis for the PerlBean.
- set_use_perl_version(VALUE)
-
Set the Perl version to use.
VALUE
is the value. Default value at initialization is'$]'
.VALUE
may not beundef
. On error an exceptionError::Simple
is thrown. - get_use_perl_version()
-
Returns the Perl version to use.
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::Dependency, PerlBean::Dependency::Import, PerlBean::Dependency::Require, PerlBean::Dependency::Use, PerlBean::Described, PerlBean::Described::ExportTag, PerlBean::Method, PerlBean::Method::Constructor, PerlBean::Style, PerlBean::Symbol
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