Pdoc

GetSet

Summary Included libraries Package variables Synopsis Description General documentation Methods

Summary
Pdoc::GetSet - Perl module to set and get key/values within blessed modules (objects).
Package variables top
Globals (from use vars definitions)
@EXPORT = qw( get set params )
$VERSION
Included modulestop
Carp qw ( cluck confess )
strict
Inherit top
Exporter
Synopsistop
    # 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');
Descriptiontop
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.
Methodstop
getDescriptionCode
paramsDescriptionCode
setDescriptionCode

Methods description

getcodetopprevnext
    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.
paramscodetopprevnext
    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.
setcodetopprevnext
    $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

getdescriptiontopprevnext
sub get {
    my $self = shift;
    my $key = shift;

    return $self->{'_getset'}->{$key};
}
paramsdescriptiontopprevnext
sub params {
    my $self = shift;
    
    print "Ret params of $self\n";
    
    return [keys %{$self->{'_getset'}} ];
}
setdescriptiontopprevnext
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.