| Config-Objective documentation | Contained in the Config-Objective distribution. |
Config::Objective::DataType - base class for Config::Objective data types
use Config::Objective;
use Config::Objective::DataType;
my $conf = Config::Objective->new('filename', {
'objname' => Config::Objective::DataType->new(
'attr1' => 0,
'attr2' => "string",
...
)
});
The Config::Objective::DataType module provides a class that encapsulates a value in an object so that it can be used with Config::Objective. Its methods can be used to manipulate the encapsulated value from the config file.
The Config::Objective::DataType class is not intended to be used to directly instantiate configuration objects, but it does support the following methods for use in subclasses:
The constructor. It can be passed a hash to set the object's attributes. The object will be created as a reference to this hash.
The value encapsulated by the object is stored in the "value" attribute. Setting this attribute in the constructor call will set the initial value for the object. If no initial value is supplied, the constructor will call the undef() method.
The Config::Objective::DataType class does not use any other attributes. However, they can be useful in subclasses.
Sets the object's value to the supplied value.
Returns the object's value.
Sets the object's value to undef.
Calls the set() method.
Mark D. Roth <roth@uiuc.edu>
perl
| Config-Objective documentation | Contained in the Config-Objective distribution. |
### ### Copyright 2002-2003 University of Illinois Board of Trustees ### Copyright 2002-2003 Mark D. Roth ### All rights reserved. ### ### Config::Objective::DataType - base class for Config::Objective data types ### ### Mark D. Roth <roth@uiuc.edu> ### Campus Information Technologies and Educational Services ### University of Illinois at Urbana-Champaign ### package Config::Objective::DataType; use strict; ############################################################################### ### constructor ############################################################################### sub new { my ($class, %opts) = @_; my ($self); $self = \%opts; bless($self, $class); $self->unset() if (!exists($self->{'value'})); return $self; } ############################################################################### ### get method ############################################################################### sub get { my ($self) = @_; # print "==> get(" . ref($self) . ")\n"; return $self->{'value'}; } ############################################################################### ### set method ############################################################################### sub set { my ($self, $value) = @_; # print "==> set(\"$value\")\n"; $self->{'value'} = $value; return 1; } ############################################################################### ### default method ############################################################################### sub default { my ($self, $value) = @_; $self->set($value); } ############################################################################### ### unset method ############################################################################### sub unset { my ($self) = @_; $self->{'value'} = undef; return 1; } ############################################################################### ### utility function for parsing arguments ############################################################################### sub _scalar_or_list { my ($self, $value) = @_; $value = [ $value ] if (! ref($value)); die "method requires scalar or list argument\n" if (ref($value) ne 'ARRAY'); return $value; } ############################################################################### ### cleanup and documentation ############################################################################### 1; __END__