Variable - class representing a session variable


Steven J. McDowall <>


Copyright 2002-2011 Applied Testing and Technology, Inc. All Rights Reserved.


use Variable;

create a new Variable object
my $sess = new Variable("variable name");

set it's title
$sess-E<gt>title("A sample session");

The Variable object contains all important information and accesors about one particular variable (i.e. option) defined within the framework. This object is normally used in conjunction with the the VariableSet object that organizes and manipulates the set of options for a whole test suite.



the name of the option


new - Create a new, unpopulated option object

$var = new Variable(name);

Creates a new option object, optionally specifying its several parameters:


the name of the option

returns a reference to the Variable object.

release - release the option


This method undefines the data structures associated with the option.

print - print the contents of the option


addOption - add a VarOption object to the list of options

$var->addOption( VarOption );

derivedfromString - fill in the derivedfrom array given a space separated string of ID tokens.

$var->derivedfromString( token-string ) ;

callDerivedFunc - call a handler for a derived variable

$value = $var->callDerivedFunc(varHash);

varHash is a hash of other variables and their values.

Returns the return value of the deriving function.

format_field - format a field for display and selection


current is a reference to the current value(s) for this item. It will be a scalar (string) or a reference to an array (for list selection items).

returns an html formatted selection item in two table cells, suitable for use in a table row.

title - accessor for the title


returns the title description.

label - synonym for title

$label = $var->label();

name - accessor for name attribute


returns a string containing the name of the option, or undef if the name is not defined.

asHtml - return the HTML rendition of a value

$str = $var->asHtml( value ) ;

isDate - check to see if the field is a date field

$stat = $var->isDate() ;

Returns 1 if the field is date only, 2 if it is a date/time field, and 0 if it is neither.

isGraphable - check to see if the field is marked graphable

$stat = $var->isGraphable() ;

isList - check to see if the field is a list field

$stat = $var->isList() ;

isNumber - is this field numeric

$field->isNumber() ;

Returns true if it is numeric, and false if it is not.

isRange - is this field a bounded range


type - accessor for the field type.

$type = $var->type( type ) ;

evaltype - accessor for the field evaluation type.

$evaltype = $var->evaltype( evaltype ) ;

class - accessor for the field class.

$class = $var->class( class ) ;

addOptions - populate option collection from value list

$var->addOptions( values );

values is a comma-separated list of values. Each value may be preceded by an asterisk, in which case it is a default value. Each value may also be followed by space-separated list of one or more values from a "dependsOn" field, enclosed in braces. E.g.,:

*value1,value2,value3{oval oval2 oval3}

Sets up option objects for each value.

setSize - set the size for the variable


size is a scalar that acts as the height for a menu, or the maximum length for a text string. In the case of a textarea, it is two values separated by an 'x'.

setFlags - set the flags for this variable


Takes a comma-separated list of flags, and sets those flags in the object. If a flag has an = after it, use the value after it as the value. Otherwise set the flag to true.

getFlags - get the flags and marshall them for saving

$str = $var->getFlags();

readonly - accessor for readonly flag

$state = $var->readonly();

ordered - accessor for ordered flag

$state = $var->ordered();

hidden - accessor for hidden flag

$state = $var->hidden() ;

default - accessor for default value

$default = $var->default() ;

setByAccount - accessor for setByAccount flag

$state = $var->setByAccount() ;

SQL_type - return the SQL type declaration for a field

$sql_type = $field->SQL_type() ;

Returns a string that can be used to define this field in a SQL table.

SQL_value - make the value SQL ready


Returns a value that is ready for insertion into a SQL store. Currently only converts date or datetime into a SQL friendly date format.

suppress - accessor for suppress attribute

$state = $var->suppress() ;

mandatory - accessor for mandatory flag

$state = $var->mandatory() ;

maxlen - accessor for maxlen attribute

$len = $var->maxlen() ;

required - accessor for required flag

$state = $var->required() ;

width - accessor for width value

$width = $var->width() ;

height - accessor for height value

$height = $var->height() ;

graphable - accessor for graphable flag

$state = $var->graphable() ;

selectable - accessor for selectable flag

$state = $var->selectable() ;

optionList - accessor for list of options

@list = $var->optionList() ;

descsList - accessor for list of descriptions

@list = $var->descsList() ;

valuesList - accessor for list of option values

@list = $var->valuesList() ;

descOf - return the description of a value

$desc = $var->descOf($value) ;

Returns the associated description if the variable is a list. If value if a reference to an array, then returns a reference to an array of descriptions.

derivedwhen - accessor for derivedwhen flag

$state = $var->derivedwhen() ;

derivedfunc - accessor for derivedfunc flag

$func = $var->derivedfunc() ;

derivedfrom - accessor for derifedfrom flag

$state = $var->derifedfrom() ;

dependson - accessor for dependson flag

$dep = $var->dependson() ;



new - create a new VarOption object

$option = new Variable::VarOption(value, title, selected, deps, obsolete);

val - accessor for val flag

$state = $option->val() ;

title - accessor for title flag

$title = $option->title() ;

selected - accessor for selected flag

$state = $option->selected() ;

dependencies - accessor for dependencies flag

$deps = $option->dependencies() ;

isObsolete - accessor for the obsolete flag

$obs = $option->isObsolete();
$obs = $option->isObsolete( 1 );

Copyright © 2000-2013 Applied Testing and Technology, Inc. All rights reserved.