The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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.

base

Passed to set_base(). Must be an ARRAY reference.

collection

Passed to set_collection().

description

Passed to set_description().

exception_class

Passed to set_exception_class(). Defaults to 'Error::Simple'.

exported

Passed to set_exported(). Defaults to 0.

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'.

synopsis

Passed to set_synopsis().

METHODS

write(FILEHANDLE)

Write the Perl class code to FILEHANDLE. FILEHANDLE is an IO::Handle object. On error an exception Error::Simple is thrown.

write_allow_isa_hash(FILEHANDLE)

Write the %ALLOW_ISA hash to FILEHANDLE. FILEHANDLE is an IO::Handle object. On error an exception Error::Simple is thrown.

write_allow_ref_hash(FILEHANDLE)

Write the %ALLOW_REF hash to FILEHANDLE. FILEHANDLE is an IO::Handle object. On error an exception Error::Simple is thrown.

write_allow_rx_hash(FILEHANDLE)

Write the %ALLOW_RX hash to FILEHANDLE. FILEHANDLE is an IO::Handle object. On error an exception Error::Simple is thrown.

write_allow_value_hash(FILEHANDLE)

Write the %ALLOW_VALUE hash to FILEHANDLE. FILEHANDLE is an IO::Handle object. On error an exception Error::Simple is thrown.

write_default_value_hash(FILEHANDLE)

Write the %DEFAULT_VALUE hash 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_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_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_exported(VALUE)

State that the PerlBean must contain code for exporter. VALUE is the value. Default value at initialization is 0. On error an exception Error::Simple is thrown.

is_exported()

Returns whether the PerlBean must contain code for exporter or not.

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_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.

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, PerlBean::Method::Constructor, PerlBean::Style

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