Parameter::Variable
- Class to define a variable in the Parameter-classes.
use Parameter::Variable;
# instantiate
my $v=Parameter::Variable->new(name=>"myvariable",value=>"myvalue",regex=>"\\w+");
# get value
my $val=$v->value();
# set value
my $v->value("myNewValue");
# get as string
my $s=$v->toString();
Class to define a variable in the Parameter-classes. It can contain a value and a set of attributes of that value.
Current attributes (besides what it inherits from the Parameter-class): value, required and regex.
Sets up the parameter-classes and returns an instance of the class.
It accepts the following options:
value The value of the Parameter::Variable-instance. Defaults to a blank value.
required Sets if the variable is required or not? Defaults to 0. 1 means true, 0 means false. Required means that the variable needs to have a value set. The enforcement of this attribute is up to the user of the Parameter-classes to execute.
regex Set the regex setting of the variable. Defaults to ".*" which accepts all. The enforcement of the regex-setting is not done by this class and must be executed by the user of the Parameter-classes.
This method is inherited from the Parameter-class. Please refer to that class for more in-depth documenation of the new()-constructor.
Returns an instance of the Parameter::Variable-class.
Get or set the regex of the variable.
In the case of set accepts one input: regex. It must be a valid perl regex-expression.
It does not check the regex or do anything with it besides storing it. It is up to the user of the Parameter-class to check and enforce the regex.
In both get and set scenarios returns the current regex-value for the variable.
Get or set the required attribute of the variable.
In the case of set accepts one input: required. 1 means true, 0 means false. If none was set for the variable in the first place it defaults to 0.
In both get and set scenarios returns the current required-value for the variable.
Get or set the sandbox attribute on the variable.
In the case of set accepts one parameter: sandbox. 1 means true, 0 means false. Default is 0 (false).
What sandbox means is up to the user of the class to define and enforce. The Parameter-classes does not define or enforce it.
In both get and set scenarios returns the current sandbox-value for the variable.
Get or set pre-escape attribute on the variable.
In the case of set accepts one parameter: preescape. 1 means true, 0 means false. Default is 1 (true).
The preescape-value is only used if escape() has been set to true. In any other case it is ignored. What the preescape-value means is that in the case of escaping, there shall be no backslashes in the beginning of the string. These are removed when calling the toString()-method of this class.
In both get and set scenarios returns the current preescape-value for the variable.
Return all the attributes of the variable as a hash.
Accepts no input.
Returns the following as a HASH-reference:
toHash => (
name => SCALAR,
value => SCALAR,
regex => SCALAR,
private => SCALAR,
required => SCALAR,
escape => SCALAR,
preescape => SCALAR,
quote => SCALAR
)
Convert the variable into a string.
Accepts no input.
Returns the value of the variable as a string, escaped and quoted according to the settings of the variable.
Set or get the value of the variable.
In the case of set, accepts one input: value.
In both set and get scenarios returns the current value of the variable.