NAME
PerlBean - Package to generate bean like Perl modules
SYNOPSIS
use strict;
use PerlBean;
use PerlBean::Attribute::Factory;
my $bean = PerlBean->new( {
package => 'MyPackage',
} );
my $factory = PerlBean::Attribute::Factory->new();
my $attr = $factory->create_attribute( {
method_factory_name => 'true',
short_description => 'something is true',
} );
$bean->add_method_factory($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
The PerlBean class models a Perl module with one package. After adding different components to the PerlBean, the Perl module can be generated.
The following sections in the code generated by a PerlBean are used to explain the concept.
PerlBeanmodule file header section-
package Circle; use 5.008; use base qw( Shape Exporter ); use strict; use warnings; use Error qw(:try); require Exporter;set_package()-
is used to set the package name in
package Circle. add_dependency()orset_dependency()-
are used to add
PerlBean::Dependencyobjects like theuseandrequirelines in the example. Note however that except foruse baseallusedependencies in the example above are set by default when initializing aPerlBeanobject without specifying adependencyoption. set_use_perl_version()-
is used to set the version number in the
use 5.008dependency. By default the version number is set to\$]. This is an exception to thePerlBean::Dependencymechanism. push_base(),set_base()orunshift_base()-
are used to express inheritance relationships. When the
PerlBeanis written, the inheritance relationships -likeShapein this example- appear in theuse baselist. TheExporterbit is there because symbols are exported bypackage Circle.
PerlBeansymbols:PerlBeancomplimentary symbols:-
# Used by _value_is_allowed our %ALLOW_ISA = ( ); # Used by _value_is_allowed our %ALLOW_REF = ( ); # Used by _value_is_allowed our %ALLOW_RX = ( 'radius' => [ '^\d*(\.\d+)?$' ], ); # Used by _value_is_allowed our %ALLOW_VALUE = ( ); # Used by _initialize our %DEFAULT_VALUE = ( ); # Package version our ($VERSION) = '$Revision: 1.0 $' =~ /\$Revision:\s+([^\s]+)/;The
our %ALLOW.*symbols above are used by the generated class to check rules that apply to thePerlBean's attributes. They are not exported. You could theoretically overwrite them. But don't do that!The
our %DEFAULT_VALUEsymbol above is used at class instantiation to set the attribute's default values of thePerlBean. It is not exported. Sometimes you need to overwrite values. That's not particularly nice and should be addressed.The
our ($VERSION)is there to allow versioning through CVS. You could overwrite it. - Preloaded section end
-
1; __END__If the
PerlBeanisautoloadedthen the code above is generated in order to autoload the methods that follow. The methodset_autoloaded()is used to change the autoload behavior of aPerlBean. NOTE: In my experience it pays to first havePerlBeans preloaded and to switch to autoload after debugging. - NAME section
-
=head1 NAME Circle - circle shapeThe package name ( which was set through
set_package()) is put inCircle -. - ABSTRACT section
-
=head1 ABSTRACT circle shape - DESCRIPTION section
-
=head1 DESCRIPTION circle shape - EXPORT section
-
This section describes all exported
PerlBean::Symbolobjects like in the following example.=head1 EXPORT By default nothing is exported. =head2 geo Geometric constants =over =item $PI The PI constant =back - CONSTRUCTOR section
-
All constructors are documented in alphabetical order in this section.
PerlBeanby default generates documentation for thenew()constructor. In theory you can overwrite thenew()constructor and hence alter the documentation thereof. Before you do so, I suggest you thoroughly contemplate this. You can of course add aPerlBean::Method::Constructorobject ( e.g.new_from_file) in order to customize construction. - METHODS section
-
All methods that aren't constructors are documented in alphabetical order in this section.
PerlBean::Methodobjects in thePerlBeanby default generate documentation for the methods. In theory you can overwrite the methods. Again, I suggest you thoroughly contemplate the consequences. - SEE ALSO section
-
L<Rectangle>, L<Shape>, L<Square>All
PerlBeanobjects inside aPerlBean::Collectionare referred in this section as listed. - BUGS section
-
None known (yet.)This section always has
None known (yet.)in it. - HISTORY section
-
First development: September 2003 Last update: September 2003This section always has
First development: C<current_date> Last update: C<current_date>in it. - AUTHOR section
-
Vincenzo ZoccaThis section always has the GECOS field from the
passwdfile. - COPYRIGHT section
-
Copyright 2003 by Vincenzo ZoccaThis section always contains the above message with the
current_yearand the GECOS field from thepasswdfile. - LICENSE section
-
This code is licensed under B<GNU GENERAL PUBLIC LICENSE>. Details on L<http://gnu.org>.This section either contains:
1) The license of the
PerlBeanwhich set through methodset_license()2) The license of the
PerlBean::Collection3) The text
TODO - Implementation section
-
This section contains the implementation of the methods and constructors. First listed are the constructors which are ordered alphabetically and
new()and_initialize()are kept near to each-other. Then the normal methods are listed alphabetically. - End of file
-
1;If the
PerlBeanis notautoloadedthen the code above is generated in order to close the file the Perl way. The methodset_autoloaded()is used to change the autoload behavior of aPerlBean. NOTE: In my experience it pays to first havePerlBeans preloaded and to switch to autoload after debugging.
CONSTRUCTOR
- new(OPT_HASH_REF)
-
Creates a new
PerlBeanobject.OPT_HASH_REFis a hash reference used to pass initialization options.OPT_HASH_REFis mandatory. On error an exceptionError::Simpleis thrown.Options for
OPT_HASH_REFmay include:abstract-
Passed to set_abstract().
autoloaded-
Passed to set_autoloaded(). Defaults to 1.
base-
Passed to set_base(). Must be an
ARRAYreference. collection-
Passed to set_collection().
dependency-
Passed to set_dependency(). Must be an
ARRAYreference. Defaults to a set ofPerlBean::Dependencyobjects 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
ARRAYreference. license-
Passed to set_license().
method-
Passed to set_method(). Must be an
ARRAYreference. method_factory-
Passed to set_method_factory(). Must be an
ARRAYreference. package-
Passed to set_package(). Mandatory option.
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
ARRAYreference. synopsis-
Passed to set_synopsis().
use_perl_version-
Passed to set_use_perl_version(). Defaults to $].
METHODS
- add_attribute( See add_method_factory() )
-
Legacy method. Writes a warning to STDERR and calls
add_method_factory(). Will be discontinued from the 4th of April 2004 on. - add_dependency( [ VALUE ... ] )
-
Add additional values on the list of 'PerlBean::Dependency' objects. Each
VALUEis 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 occurrences of the same key yield in the last occurring 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::Simpleis thrown. - add_export_tag_description( [ VALUE ... ] )
-
Add additional values on the list of 'PerlBean::Described::ExportTag' objects. Each
VALUEis 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 occurrences of the same key yield in the last occurring 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::Simpleis thrown. - add_method( [ VALUE ... ] )
-
Add additional values on the list of 'PerlBean::Method' objects. Each
VALUEis 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 occurrences of the same key yield in the last occurring 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::Simpleis thrown. - add_method_factory( [ VALUE ... ] )
-
Add additional values on the list of 'PerlBean::Method::Factory' objects. Each
VALUEis an object out of which the id is obtained through methodget_method_factory_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 occurrences of the same key yield in the last occurring 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::Simpleis thrown. - add_symbol( [ VALUE ... ] )
-
Add additional values on the list of 'PerlBean::Symbol' objects. Each
VALUEis 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 occurrences of the same key yield in the last occurring 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::Simpleis thrown. - delete_attribute( See delete_method_factory() )
-
Legacy method. Writes a warning to STDERR and calls
delete_method_factory(). Will be discontinued from the 4th of April 2004 on. - delete_dependency(ARRAY)
-
Delete elements from the list of 'PerlBean::Dependency' objects. Returns the number of deleted elements. On error an exception
Error::Simpleis 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::Simpleis thrown. - delete_method(ARRAY)
-
Delete elements from the list of 'PerlBean::Method' objects. Returns the number of deleted elements. On error an exception
Error::Simpleis thrown. - delete_method_factory(ARRAY)
-
Delete elements from the list of 'PerlBean::Method::Factory' objects. Returns the number of deleted elements. On error an exception
Error::Simpleis thrown. - delete_symbol(ARRAY)
-
Delete elements from the list of 'PerlBean::Symbol' objects. Returns the number of deleted elements. On error an exception
Error::Simpleis thrown. - exists_attribute( See exists_method_factory() )
-
Legacy method. Writes a warning to STDERR and calls
exists_method_factory(). Will be discontinued from the 4th of April 2004 on. - exists_base(ARRAY)
-
Returns the count of items in
ARRAYthat are in the list of class names in use base. - exists_dependency(ARRAY)
-
Returns the count of items in
ARRAYthat are in the list of 'PerlBean::Dependency' objects. - exists_export_tag_description(ARRAY)
-
Returns the count of items in
ARRAYthat are in the list of 'PerlBean::Described::ExportTag' objects. - exists_method(ARRAY)
-
Returns the count of items in
ARRAYthat are in the list of 'PerlBean::Method' objects. - exists_method_factory(ARRAY)
-
Returns the count of items in
ARRAYthat are in the list of 'PerlBean::Method::Factory' objects. - exists_symbol(ARRAY)
-
Returns the count of items in
ARRAYthat are in the list of 'PerlBean::Symbol' objects. - get_abstract()
-
Returns the PerlBean's abstract (a one line description of the module).
- get_base( [ INDEX_ARRAY ] )
-
Returns an
ARRAYcontaining the list of class names in use base.INDEX_ARRAYis 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. - get_collection()
-
Returns class to throw when exception occurs.
- get_description()
-
Returns the PerlBean description.
- get_exception_class()
-
Returns class to throw when exception occurs.
- get_license()
-
Returns the software license for the PerlBean.
- get_package()
-
Returns package name.
- get_short_description()
-
Returns the short PerlBean description.
- get_synopsis()
-
Returns the synopsis for the PerlBean.
- get_use_perl_version()
-
Returns the Perl version to use.
- is_autoloaded()
-
Returns whether the methods in the PerlBean are autoloaded or not.
- is_singleton()
-
Returns whether the package is a singleton and an
instance()method is implemented or not. - keys_attribute( See keys_method_factory() )
-
Legacy method. Writes a warning to STDERR and calls
keys_method_factory(). Will be discontinued from the 4th of April 2004 on. - keys_dependency()
-
Returns an
ARRAYcontaining the keys of the list of 'PerlBean::Dependency' objects. - keys_export_tag_description()
-
Returns an
ARRAYcontaining the keys of the list of 'PerlBean::Described::ExportTag' objects. - keys_method()
-
Returns an
ARRAYcontaining the keys of the list of 'PerlBean::Method' objects. - keys_method_factory()
-
Returns an
ARRAYcontaining the keys of the list of 'PerlBean::Method::Factory' objects. - keys_symbol()
-
Returns an
ARRAYcontaining the keys of the list of 'PerlBean::Symbol' objects. - pop_base()
-
Pop and return an element off the list of class names in use base. On error an exception
Error::Simpleis thrown. - push_base(ARRAY)
-
Push additional values on the list of class names in use base.
ARRAYis the list value. The push may not yield to multiple identical elements in the list. Hence, multiple occurrences of the same element are ignored. On error an exceptionError::Simpleis thrown. - set_abstract(VALUE)
-
Set the PerlBean's abstract (a one line description of the module).
VALUEis the value. On error an exceptionError::Simpleis thrown. - set_attribute( See set_method_factory() )
-
Legacy method. Writes a warning to STDERR and calls
set_method_factory(). Will be discontinued from the 4th of April 2004 on. - set_autoloaded(VALUE)
-
State that the methods in the PerlBean are autoloaded.
VALUEis the value. Default value at initialization is1. On error an exceptionError::Simpleis thrown. - set_base(ARRAY)
-
Set the list of class names in use base absolutely.
ARRAYis the list value. Each element in the list is allowed to occur only once. Multiple occurrences of the same element yield in the first occurring element to be inserted and the rest to be ignored. On error an exceptionError::Simpleis thrown. - set_collection(VALUE)
-
Set class to throw when exception occurs.
VALUEis the value. On error an exceptionError::Simpleis thrown. - set_dependency( [ VALUE ... ] )
-
Set the list of 'PerlBean::Dependency' objects absolutely using values. Each
VALUEis 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 occurrences of the same key yield in the last occurring 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::Simpleis thrown. Defaults value at initialization is a set ofPerlBean::Dependencyobjects that yields to:use strict; use warnings; use Error qw(:try); - set_description(VALUE)
-
Set the PerlBean description.
VALUEis the value. On error an exceptionError::Simpleis thrown. - set_exception_class(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. - set_export_tag_description( [ VALUE ... ] )
-
Set the list of 'PerlBean::Described::ExportTag' objects absolutely using values. Each
VALUEis 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 occurrences of the same key yield in the last occurring 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::Simpleis thrown. - set_license(VALUE)
-
Set the software license for the PerlBean.
VALUEis the value. On error an exceptionError::Simpleis thrown. - set_method( [ VALUE ... ] )
-
Set the list of 'PerlBean::Method' objects absolutely using values. Each
VALUEis 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 occurrences of the same key yield in the last occurring 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::Simpleis thrown. - set_method_factory( [ VALUE ... ] )
-
Set the list of 'PerlBean::Method::Factory' objects absolutely using values. Each
VALUEis an object out of which the id is obtained through methodget_method_factory_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 occurrences of the same key yield in the last occurring 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::Simpleis thrown. - set_package(VALUE)
-
Set package name.
VALUEis the value.VALUEmay not beundef. On error an exceptionError::Simpleis thrown. - set_short_description(VALUE)
-
Set the short PerlBean description.
VALUEis the value. Default value at initialization isNO DESCRIPTION AVAILABLE. On error an exceptionError::Simpleis thrown. - set_singleton(VALUE)
-
State that the package is a singleton and an
instance()method is implemented.VALUEis the value. Default value at initialization is0. On error an exceptionError::Simpleis thrown. - set_symbol( [ VALUE ... ] )
-
Set the list of 'PerlBean::Symbol' objects absolutely using values. Each
VALUEis 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 occurrences of the same key yield in the last occurring 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::Simpleis thrown. - set_synopsis(VALUE)
-
Set the synopsis for the PerlBean.
VALUEis the value. On error an exceptionError::Simpleis thrown. - set_use_perl_version(VALUE)
-
Set the Perl version to use.
VALUEis the value. Default value at initialization is$].VALUEmay not beundef. On error an exceptionError::Simpleis thrown. - shift_base()
-
Shift and return an element off the list of class names in use base. On error an exception
Error::Simpleis thrown. - unshift_base(ARRAY)
-
Unshift additional values on the list of class names in use base.
ARRAYis the list value. The push may not yield to multiple identical elements in the list. Hence, multiple occurrences of the same element are ignored. On error an exceptionError::Simpleis thrown. - values_attribute( See values_method_factory() )
-
Legacy method. Writes a warning to STDERR and calls
values_method_factory(). Will be discontinued from the 4th of April 2004 on. - values_dependency( [ KEY_ARRAY ] )
-
Returns an
ARRAYcontaining the values of the list of 'PerlBean::Dependency' objects. IfKEY_ARRAYcontains one or moreKEYs the values related to theKEYs are returned. If noKEYs specified all values are returned. - values_export_tag_description( [ KEY_ARRAY ] )
-
Returns an
ARRAYcontaining the values of the list of 'PerlBean::Described::ExportTag' objects. IfKEY_ARRAYcontains one or moreKEYs the values related to theKEYs are returned. If noKEYs specified all values are returned. - values_method( [ KEY_ARRAY ] )
-
Returns an
ARRAYcontaining the values of the list of 'PerlBean::Method' objects. IfKEY_ARRAYcontains one or moreKEYs the values related to theKEYs are returned. If noKEYs specified all values are returned. - values_method_factory( [ KEY_ARRAY ] )
-
Returns an
ARRAYcontaining the values of the list of 'PerlBean::Method::Factory' objects. IfKEY_ARRAYcontains one or moreKEYs the values related to theKEYs are returned. If noKEYs specified all values are returned. - values_symbol( [ KEY_ARRAY ] )
-
Returns an
ARRAYcontaining the values of the list of 'PerlBean::Symbol' objects. IfKEY_ARRAYcontains one or moreKEYs the values related to theKEYs are returned. If noKEYs specified all values are returned. - write(FILEHANDLE)
-
Write the Perl class code to
FILEHANDLE.FILEHANDLEis anIO::Handleobject. On error an exceptionError::Simpleis thrown.
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::Method::Factory, PerlBean::Style, PerlBean::Symbol
BUGS
- OS dependency
-
PerlBeanis written on/for Unix. File handling and system file access should be enhanced to be OS independent. - PerlBean rules
-
- Symbols
-
I am not satisfied with the
our %ALLOW.*symbols that are used to check rules that apply to thePerlBean's attributes. They pollute the class' name space. Also there are too many symbols in use. Once I will restructure these into one hash ( e.g._RULES_).
- PerlBean::Attribute
-
- Default values
-
Currently, default values can only be defined fixed. Expressions that are evaluated at module load and expressions that are evaluated at class instantiation would make sense.
Also, their representations in code and in pod have issues with special characters.
- Allow/deny undef
-
Currently, allow/deny of
undefis handled poorly by_value_is_allowed(). That has to get better. - A lock property
-
In order to deny attributes being changed after they are set.
- SEE ALSO section
-
I am not satisfied with the long lists in the SEE ALSO section.
PerlBeanobjects must get a documentation scope or some other restriction scheme. I don't know exactly yet. - BUGS section
-
The BUGS section always has
None known (yet.)in it. That must improve. - HISTORY section
-
The
HISTORYsection always hasFirst development: C<current_date> Last update: C<current_date>in it. That must improve. - TODO section
-
I need a
TODOsection.
HISTORY
First development: November 2002 Last update: September 2003
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