NAME

Parameter::Group - Class to handle groups of parameters - either other sub-groups and/or variables.

SYNOPSIS

 use Parameter::Group;

 # create instance
 my $g=Parameter::Group->new();

 # create a Parameter-object
 my $v=Parameter::Variable->new();

 # add a Parameter-object to the group
 $g->add($v);

 # create a variable object and add it to the group instance
 $g=addVariable("myvariable","somevalue",".*");

 # create a sub-group-object and add it to the group instance
 $g->addGroup("mygroup");

 # add variable to subgroup
 $g->get("mygroup")->addVariable("somename","othervalue");
 
 # add variable after another named variable
 $g->addVariableAfter("myvariable","newvariablename","value");

 # add variable before another named variable
 $g->addVariableBefore("newvariablename","myvarname","a_value");

 # make a variable required and public
 $g->addVariable("mypublicvariable","somevalue",1,0);

 # create a group and tell it to quote its content parameters (sub-groups and/or variables)
 $g->addGroup("myquotedgroup",undef,1);

 # remove a named parameter
 $g->remove("mypublicvariable");

 # enumerate objects (sub-groups and variables)
 my $e=$g->enum();

 # get next parameter
 while (my $par=$g->getNextParameter()) {
    print "Parameter value is: $par\n";
 }
 
 # enumerate objects
 my $pars=$g->enumObjects();

 # enumerate unique objects
 my $uni=$g->enumUniqueObjects();

 # enumerate required objects
 my $r=$g->enumRequiredObjects();

 # enumerate private objects
 $p=$g->enumPrivateObjects();

 # get a specific named object
 my $o=$g->get("objectname");

 # check if an object exists (sub-groups or variables)
 if ($g->exists("objectname")) {}

 # get if group is to have no space between parameters or not?
 my $ns=$g->noSpace();

 # get all parameters in group as a string
 my $s=$g->toString();

 # get number of objects in group (sub-groups and/or variables)
 my $c=$g->count();

DESCRIPTION

Class to handle groups of parameters, either other sub-groups and/or variables.

This class is a sub-class of the Parameter-class. Usually when using the Parameter-class one only instantiates a Parameter::Group-class.

A parameter-group can contain both other sub-groups as well as parameters. It does not allow the creation or addition of groups or variables that have the same name as other groups and variables already added. This is to ensure unique naming in the entire parameter-group, so that one can use the objects by referring to them by name (ie. parameter-name). One can circumvent this requirement in several ways, but we admonish the user to adhere to a group- and parameter unique use.

When addressing Parameter-objects in this class, you can refer to them or get them by using the get()-method. It works hierarchically and will recurse into sub-groups to find the group or variable that you are looking for. Also methods that take parameter-name as an option will recurse to find the object if not otherwise stated. The expection is sub-groups where they will not recurse up the group-tree, only down the group-tree.

An overview of concepts:

CONSTRUCTOR

new()

The method is inherited from the parent Parameter-class, but in addition sets some internal settings that are unique to the Parameter::Group-class.

This method returns an instantiated class upon success. Please refer to the documentation of the Parameter-class for more information.

METHODS

add()

Adds a parameter object to the group.

Accepts the following input in this order:

This method returns 1 upon success, 0 upon failure. Please check the error()-method for more information upon failure.

remove()

Attempt to remove named parameter.

Accepts the following input: name. This is the name of the parameter to attempt to locate and remove.

This method returns 1 upon success, 0 upon failure. Please check the error()-method for more information upon failure.

Please note that all instances of a named parameter is removed when invoking this method.

addGroup()

Adds a sub-group object to the group at the end of current objects.

Accepts the following parameters in this order:

Upon success this method returns the group-instance it created and undef upon failure. Please check the error()-method for more information upon failure.

addGroupAfter()

Adds a sub-group in this group after the given parameter name.

This method is a wrapper for the addGroup-method for ease of use.

Accepts the following parameters in this order:

Returns the instance of the class-created upon success, undef upon failure. Please check the error()-method for more information.

addGroupBefore()

Adds a sub-group in this group before the given parameter name.

This method is a wrapper for the addGroup-method for ease of use. It also works similarly to the addGroupAfter()-method. Check the documentation for that method for more information.

addVariable()

Adds a variable in this group.

If the variable name exists already, that Parameter::Variable-object is added to the group. Variables can be used several places, but all variables should still have unique names.

Accepts the following options in this order:

Upon success returns 1, 0 on failure. Please check the error()-method for more information upon failure.

addVariableAfter()

Adds a variable after the given parameter name.

This is a wrapper around the addVariable()-method. It accepts options in the following order: parname (name of parameter after which to add this variable), name (variable name), value (value of variable), regex, required, private, escape, quote, sandbox and preescape. Please see the addVariable()-method for more information about the options.

Please note that if given variable name already exists, that Parameter::Variable-instance is added. If it doesn't exist, it will be created and then added.

Returns 1 upon success, 0 upon failure. Please see the error()-method for more information upon failure.

addVariableBefore()

Adds a variable before the given parameter name.

This is a wrapper around the addVariable()-method. It accepts options in the following order: parname (name of parameter before which to add this variable), name (variable name), value (value of variable), regex, required, private, escape, quote, sandbox and preescape. Please see the addVariable()-method for more information about the options.

Please note that if given variable name already exists, that Parameter::Variable-instance is added. If it doesn't exist, it will be created and then added.

Returns 1 upon success, 0 upon failure. Please see the error()-method for more information upon failure.

count()

Returns the number of Parameter-objects in the group.

No input accepted.

enum()

Enumerate the objects that the group-instance contains.

Accepts no input.

Returns a LIST-reference of Parameter-classes

enumObjects()

Enumerate the object names of the group.

Please note that object names enumerated can be repeated (for Parameter::Variable-objects) and show the actual order of the Parameter-group.

Returns a reference to a LIST of object names. Please note that the list can be empty.

enumPrivateObjects()

Enumerate the private objects of the group.

This returns the unique, private objects in the group and its sub-groups.

No input is accepted.

Returns a LIST-reference of object names.

enumRequiredObjects()

Enumerate the required objects of the group.

This returns the unique and required objects of the group and its sub-groups.

No input is accepted.

Returns a LIST-reference of object names.

enumUniqueObject()

Enumerate the unique objects of the group.

This returns the unique object names of the group and its sub-groups.

No input is accepted.

Returns a LIST-reference of the object names.

exists()

Checks if a given object name exists in group or its sub-groups.

Accepts one input: object name.

Returns 1 if it exists, 0 if it does not.

get()

Get a names object-instance.

Accepts one input: object name.

Returns the object-instance if the object exists in the top group or its sub-groups, undef upon failure. This method will go to the top-most parent-group and start asking for the object there while recursing down the possible groups in the Parameter-tree. It will return the first match from the top-down.

Please check error()-method upon failure.

getFirst()

Get the first object in the group.

Accepts no input.

Returns the object instance of the first object in the group.

getFirstParameter()

Get the first parameter of the group-instance, if any.

Accepts no input.

Returns the value of the first parameter if any. Undef if no value exists.

getNext()

Gets the next object in the group.

Accepts no input.

Gets the next object in the group after a call to getFirst(), resetGetNext() or getNext().

Returns an object-reference upon success, undef if there are no more objects.

getNextParameter()

Returns the next parameters value in the group.

Accepts no input.

Gets the next parameters value in the group or its sub-groups after a call to getFirstParameter(), resetgetNextParameter() or getNextParameter().

Returns a value upon success, undef if there are no more parameter values to fetch.

location()

Get the location of a named object within group or sub-group.

Accepts one input:

Returns a LIST-reference. The list reference can be empty if the named object could not be found.

The LIST-reference structure is as follows:

[GROUP-NAME,POSITION]

GROUP-NAME is the name of the first group or sub-group that contains the object (variables may exist in several places). POSITION is the first numbered position within GROUP-NAME that the object exists.

noSpace()

Get or set if group is to have no space between its parameters.

Accepts only one input: nospace. Nospace sets if the group is to have no space or not. 1 means true (no space), 0 means false. It defaults to 0 (parameters are to have space between them).

If no input is given, the method returns the current noSpace-setting of the group. Setting the noSpace setting returns the setting after it has been set.

resetGetNext()

Reset to get the next group object.

Accepts no input.

Resets the fetching of group objects by the method getNext().

Returns 1.

resetGetNextParameter()

Resets the getting of next parameter value and starts at the beginning of the parameter list.

Accepts no input.

Always returns 1.

toString()

Convert all the group- and sub-group parameters into a string.

Accepts no input.

Returns the rendered groups parameters and their values as a string.

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 1003:

=cut found outside a pod block. Skipping to next block.