NAME
CodeGen::PerlBean - Class to generate bean like Perl modules
SYNOPSIS
use strict;
use IO::File;
use CodeGen::PerlBean;
use CodeGen::PerlBean::Attribute::Factory;
# Attribute descriptions
my @attr = (
{
attribute_name => 'attribute',
type => 'MULTI',
unique => 1,
short_description => 'the list \'CodeGen::PerlBean::Attribute\' objects',
ordered => 1,
},
{
attribute_name => 'exception_class',
allow_empty => 0,
default_value => 'Error::Simple',
short_description => 'class to throw when exception occurs',
},
{
attribute_name => 'package',
allow_empty => 0,
default_value => 'main',
short_description => 'package name',
},
{
attribute_name => 'short_description',
short_description => 'attribute description',
default_value => 'NO DESCRIPTION AVAILABLE',
},
);
# Create CodeGen::PerlBean object
my $bean = CodeGen::PerlBean->new ({package => 'CodeGen::PerlBean'});
# Add CodeGen::PerlBean::Attribute objects
foreach my $attr (@attr) {
$bean->pushAttribute (CodeGen::PerlBean::Attribute::Factory->attribute ($attr));
}
# Write the CodeGen::PerlBean object to a file
my $fh = IO::File->new ('> PerlBean-gen.pm');
$bean->write ($fh);
ABSTRACT
Code generation for bean like Perl modules
DESCRIPTION
CodeGen::PerlBean generates bean like Perl module code. 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 CodeGen::PerlBean::Attribute objects. However, CodeGen::PerlBean::Attribute are best generated using CodeGen::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 to 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 CodeGen::PerlBean and CodeGen::PerlBean::Attribute are actually generated using this method.
CONSTRUCTOR
- new ([OPT_HASH_REF])
-
Creates a new
CodeGen::PerlBeanobject.OPT_HASH_REFis a hash reference used to pass initialization options. On error an exceptionError::Simpleis thrown.Options for
OPT_HASH_REFmay include:- attribute
-
Passed to "setAttribute ()". Must be an
ARRAYreference. - exception_class
-
Passed to "setExceptionClass ()". Defaults to Error::Simple.
- package
-
Passed to "setPackage ()". Defaults to main.
- short_description
-
Passed to "setShortDescription ()".
METHODS
- setAttribute (ARRAY)
-
Set the list 'CodeGen::PerlBean::Attribute' objects 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. - pushAttribute (ARRAY)
-
Push additional values on the list 'CodeGen::PerlBean::Attribute' objects.
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. - popAttribute ()
-
Pop and return an element off the list 'CodeGen::PerlBean::Attribute' objects. On error an exception
Error::Simpleis thrown. - shiftAttribute ()
-
Shift and return an element off the list 'CodeGen::PerlBean::Attribute' objects. On error an exception
Error::Simpleis thrown. - unshiftAttribute (ARRAY)
-
Unshift additional values on the list 'CodeGen::PerlBean::Attribute' objects.
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. - hasAttribute (ARRAY)
-
Returns the count of items in
ARRAYthat are in the list 'CodeGen::PerlBean::Attribute' objects. - getAttribute ()
-
Returns an
ARRAYcontaining the list 'CodeGen::PerlBean::Attribute' objects. - 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.
- 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 attribute description.
VALUEis the value. On error an exceptionError::Simpleis thrown. - getShortDescription ()
-
Returns attribute description.
- write (FILEHANDLE)
-
Write the Perl class code to
FILEHANDLE.FILEHANDLEis anIO::Handleobject. On error an exceptionError::Simpleis thrown.
SEE ALSO
CodeGen::PerlBean::Attribute CodeGen::PerlBean::Attribute::Boolean CodeGen::PerlBean::Attribute::Factory CodeGen::PerlBean::Attribute::Multi CodeGen::PerlBean::Attribute::Multi::Ordered CodeGen::PerlBean::Attribute::Multi::Unique CodeGen::PerlBean::Attribute::Multi::Unique::Ordered CodeGen::PerlBean::Attribute::Single
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 CodeGen::PerlBean module hierarchy for Perl by Vincenzo Zocca.
The CodeGen::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 CodeGen::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 CodeGen::PerlBean module hierarchy; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA