Pdoc
GetSet
Pdoc::GetSet - Perl module to set and get key/values within blessed modules (objects).
|
| Globals (from use vars definitions) |
| @EXPORT = qw( get set params ) |
| $VERSION |
| Carp qw ( cluck confess ) |
| strict |
# 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');
|
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 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
| AUTHOR |
top |
Copyright (c) 2000 by Raphael Leplae (lp1@sanger.ac.uk). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|