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 exception Error::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 of PerlBean::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 an IO::Handle object. On error an exception Error::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 exception Error::Simple is thrown.

VALUE must match regular expression:
^.*$
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 method get_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 exception Error::Simple is thrown.

The values in ARRAY must be a (sub)class of:
PerlBean::Attribute
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 method get_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 exception Error::Simple is thrown.

The values in ARRAY must be a (sub)class of:
PerlBean::Attribute
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. If KEY_ARRAY contains one or more KEYs the values related to the KEYs are returned. If no KEYs 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 is 1. On error an exception Error::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 exception Error::Simple is thrown.

The values in ARRAY must match regular expression:
^\S+$
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 exception Error::Simple is thrown.

The values in ARRAY must match regular expression:
^\S+$
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 exception Error::Simple is thrown.

The values in ARRAY must match regular expression:
^\S+$
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 exception Error::Simple is thrown.

VALUE must be a (sub)class of:
PerlBean::Collection
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 method get_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 exception Error::Simple is thrown. Defaults value at initialization is a set of PerlBean::Dependency objects that yields to:

use strict;
use warnings;
use Error qw(:try);
The values in ARRAY must be a (sub)class of:
PerlBean::Dependency
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 method get_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 exception Error::Simple is thrown.

The values in ARRAY must be a (sub)class of:
PerlBean::Dependency
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. If KEY_ARRAY contains one or more KEYs the values related to the KEYs are returned. If no KEYs specified all values are returned.

set_description(VALUE)

Set the PerlBean description. VALUE is the value. On error an exception Error::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 be undef. On error an exception Error::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 method get_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 exception Error::Simple is thrown.

The values in ARRAY must be a (sub)class of:
PerlBean::Described::ExportTag
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 method get_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 exception Error::Simple is thrown.

The values in ARRAY must be a (sub)class of:
PerlBean::Described::ExportTag
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. If KEY_ARRAY contains one or more KEYs the values related to the KEYs are returned. If no KEYs specified all values are returned.

set_license(VALUE)

Set the software license for the PerlBean. VALUE is the value. On error an exception Error::Simple is thrown.

VALUE must match regular expression:
.*
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 method get_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 exception Error::Simple is thrown.

The values in ARRAY must be a (sub)class of:
PerlBean::Method
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 method get_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 exception Error::Simple is thrown.

The values in ARRAY must be a (sub)class of:
PerlBean::Method
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. If KEY_ARRAY contains one or more KEYs the values related to the KEYs are returned. If no KEYs specified all values are returned.

set_package(VALUE)

Set package name. VALUE is the value. Default value at initialization is 'main'. VALUE may not be undef. On error an exception Error::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 exception Error::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 is 0. On error an exception Error::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 method get_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 exception Error::Simple is thrown.

The values in ARRAY must be a (sub)class of:
PerlBean::Symbol
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 method get_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 exception Error::Simple is thrown.

The values in ARRAY must be a (sub)class of:
PerlBean::Symbol
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. If KEY_ARRAY contains one or more KEYs the values related to the KEYs are returned. If no KEYs specified all values are returned.

set_synopsis(VALUE)

Set the synopsis for the PerlBean. VALUE is the value. On error an exception Error::Simple is thrown.

VALUE must match regular expression:
.*
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 be undef. On error an exception Error::Simple is thrown.

VALUE must match regular expression:
^v?\d+(\.[\d_]+)*
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