| PerlBean documentation | Contained in the PerlBean distribution. |
PerlBean::Attribute::Factory - factory package to generate PerlBean::Attribute objects
use strict;
use PerlBean::Attribute::Factory;
my $factory = PerlBean::Attribute::Factory->new();
my $attr = $factory->create_attribute( {
type => 'BOOLEAN',
method_factory_name => 'true',
short_description => 'something is true',
} );
PerlBean::Attribute object factory
PerlBean::Attribute::Factory objects create instances of PerlBean::Attribute objects.
Creates a new PerlBean::Attribute::Factory object.
Returns PerlBean::Attribute objects based on OPT_HASH_REF. OPT_HASH_REF is a hash reference used to pass initialization options. The selected subclass of PerlBean::Attribute is initialized using OPT_HASH_REF. On error an exception Error::Simple is thrown.
Options for OPT_HASH_REF used by this method may include:
Boolean flag. States that the returned attribute must be unique, associative MULTI. Defaults to 0. Only makes sense if type is MULTI and unique is true.
Boolean flag. States that the returned attribute must be unique, associative MULTI. Defaults to 0. Only makes sense if type is MULTI and unique is true.
Boolean flag. States that the returned attribute must be an ordered list. Defaults to 0. Only makes sense if type is MULTI.
If type is BOOLEAN a PerlBean::Attribute::Boolean, on SINGLE a PerlBean::Attribute::Single and on MULTI a PerlBean::Attribute::Multi is returned. Defaults to 'SINGLE'. NOTE: type has precedence over ordered and unique.
Boolean flag. States that the items in the MULTI attribute must be unique. Defaults to 0. Only makes sense if type is MULTI.
Options for OPT_HASH_REF passed to package PerlBean::Attribute may include:
default_valuePassed to set_default_value().
exception_classPassed to set_exception_class(). Defaults to 'Error::Simple'.
mandatoryPassed to set_mandatory(). Defaults to 0.
method_basePassed to set_method_base().
method_factory_namePassed to set_method_factory_name(). Mandatory option.
perl_beanPassed to set_perl_bean().
short_descriptionPassed to set_short_description().
Options for OPT_HASH_REF passed to package PerlBean::Attribute::Single may include:
allow_emptyPassed to set_allow_empty(). Defaults to 1.
allow_isaPassed to set_allow_isa(). Must be an ARRAY reference.
allow_refPassed to set_allow_ref(). Must be an ARRAY reference.
allow_rxPassed to set_allow_rx(). Must be an ARRAY reference.
allow_valuePassed to set_allow_value(). Must be an ARRAY reference.
PerlBean, PerlBean::Attribute, PerlBean::Attribute::Boolean, 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
None known (yet.)
First development: November 2002 Last update: September 2003
Vincenzo Zocca
Copyright 2002, 2003 by Vincenzo Zocca
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
| PerlBean documentation | Contained in the PerlBean distribution. |
package PerlBean::Attribute::Factory; use 5.005; use strict; use warnings; use AutoLoader qw(AUTOLOAD); use Error qw(:try); # Package version our ( $VERSION ) = '$Revision: 1.0 $' =~ /\$Revision:\s+([^\s]+)/; 1; __END__
sub new { my $class = shift; my $self = {}; bless( $self, ( ref($class) || $class ) ); return( $self->_initialize(@_) ); } sub _initialize { my $self = shift; my $opt = defined($_[0]) ? shift : {}; # Check $opt ref($opt) eq 'HASH' || throw Error::Simple("ERROR: PerlBean::Attribute::Factory::_initialize, first argument must be 'HASH' reference."); # Return $self return($self); } sub create_attribute { my $self = shift; my $opt = shift || {}; # Switch attribute type if ( ! defined($opt->{type} ) || $opt->{type} eq 'SINGLE') { require PerlBean::Attribute::Single; return( PerlBean::Attribute::Single->new($opt) ); } elsif ( $opt->{type} eq 'BOOLEAN' ) { require PerlBean::Attribute::Boolean; return( PerlBean::Attribute::Boolean->new($opt) ); } elsif ( $opt->{type} eq 'MULTI' ) { if ( $opt->{unique} ) { if ( $opt->{ordered} ) { require PerlBean::Attribute::Multi::Unique::Ordered; return( PerlBean::Attribute::Multi::Unique::Ordered->new($opt) ); } elsif ( $opt->{associative} ) { if ( $opt->{method_key} ) { require PerlBean::Attribute::Multi::Unique::Associative::MethodKey; return( PerlBean::Attribute::Multi::Unique::Associative::MethodKey->new($opt) ); } else { require PerlBean::Attribute::Multi::Unique::Associative; return( PerlBean::Attribute::Multi::Unique::Associative->new($opt) ); } } else { require PerlBean::Attribute::Multi::Unique; return( PerlBean::Attribute::Multi::Unique->new($opt) ); } } else { require PerlBean::Attribute::Multi::Ordered; return( PerlBean::Attribute::Multi::Ordered->new($opt) ); } } else { throw Error::Simple("ERROR: PerlBean::Attribute::Factory::attribute, option 'type' must be one of 'BOOLEAN', 'SINGLE' or 'MULTI' and NOT '$opt->{type}'."); } }