Pdoc
GetSet
Summary
Pdoc::GetSet - Perl module to set and get key/values within blessed modules (objects).
Package variables
No package variables defined.
Included modules
Carp qw ( cluck confess )
strict
Inherit
Exporter
Synopsis
# In a Perl module
use Pdoc::GetSet;
# Inherit get and set methods
use vars qw(@ISA);
@ISA = qw( Pdoc::GetSet );
# Set a value
$self->set('key', $value);
# Get the value
my $value = $self->get('key');
Description
Pdoc::GetSet works in the context of a blessed Perl module (object) by allowing to assign and retrieve parameters through a 'get' and 'set' method. The methods will use a key in the object hash table reference called $self->{'_getset'} that will hold all the parameters + values.
Methods
Methods description
my $value = $self->get('key');
Pdoc::GetSet::get is the method responsible for the retrieval of the value associated with a key. The unique argument is the key name referring to the value. |
foreach my $key (@{$self->params()}) {
print "Key = $key, value = ", $self->get($key), "\n";
}
Pdoc::GetSet::params returns all the parameter names assigned with the 'set' method. |
$self->set('key', $value);
Pdoc::GetSet::set is the method responsible for the assignment of a value to a key. The first argument is the key name and the second argument is the value. |
Methods code
sub get
{ my $self = shift;
my $key = shift;
return $self->{'_getset'}->{$key}; } |
sub params
{ my $self = shift;
print "Ret params of $self\n";
return [keys %{$self->{'_getset'}} ]; } |
sub set
{ my $self = shift;
my $key = shift;
my $value = shift;
$self->{'_getset'}->{$key} = $value; } |
General documentation
Copyright (c) 2000-2006 by Raphael Leplae (
raphael@scmbb.ulb.ac.be). All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.