ReqFields - class to represent and manipulate requirement schema
Shane P. McCarron <shane@aptest.com>
Copyright 1999-2011 Applied Testing and Technology, Inc. All Rights Reserved.
use ReqFields; # create a schema object my $rfields = new ReqFields(suiteName); # get a handle to the hash of a schema field $field = $rfields->field(name); # get a handle to a hash of all fields $fieldHash = $rfields->field(); # structure a value in a schema instance $output = $rfields->fieldEntry(fieldName, value, edit);
The ReqFields object is a tool to instantiate the schema for a test suite.
$rfields = new ReqFields(suite, edit);
Creates a new schema object.
the name of a test suite to access.
returns a reference to the schema object. Note that if there is no requirements field definition file, an empty object is returned.
$state = $rfields->edit(); $state = $rfields->edit(boolean);
$mode = $rfields->mode(); $mode = $rfields->mode( string );
The mode is one of 'view', 'edit', 'run', 'report'.
@mlists = $rfields->multiLists() ;
$ref = $rfields->field(); $ref = $rfields->field(name);
@list = $rfields->flist() ;
Returns the list of fields defined in the schema.
$output = $rfields->fieldEntryWrap(reqRef, field, value, suffix, fn);
reqRef - reference to a Requirement object
field - the field we are using
value - the value the field has in the test case
suffix - an optional suffix to attach to input elements
fn - pointer to a function to call to wrap each value. The arguments passed to the function are the field name and the value (which may be special in the case of an menu).
$output = $rfields->fieldEntryVar(test, field, value, suffix, fn);
test - a handle to the test case instance
field - the field we are using
value - the value the field has in the test case
suffix - a suffix to attach to HTML form variable names
fn - the name of a javascript function to call on change
$output = $rfields->fieldEntry(test, field, value [, row]);
testcase - reference to a TestCase object
test - a handle to the test case instance
name - the field we are using
value - the value the field has in the test case
row - the row in an inset table. If defined, is used as a suffix for the CGI variable name.
$table = $rfields->buildSelectorTable( currentSelection, allowNonSelectable, showSpecials, showCounts, showDynamic );
The arguments are passed through to fieldSelection().
($testSels, $warnings) = $s->getSelsFromArgs( $hashRef ) ;
hashRef is a reference to a hash of CGI parameters and their values.
If there are any issues with parsing, those issues are pushed into the referenced hash as key_WARNING.
Returns a reference to a hash of selectors suitable for pushing into the selector method, and a string of warnings suitable for displaying (if any).
$output = $rfields->fieldSelection( field, currentSelection, allowNonSelectable, showSpecials, showCounts, showDynamic, multiple );
field is the field to present
currentSelection is a reference to an array of existing selections or a comma-separated string of current selections.
allowNonSelectable is a boolean that indicates whether even non-selectable fields should be presented (for use in report and edit selectors).
showSpecials is a boolean that indicates whether the special isCS and isRE selectors should also be shown on items that support those flags.
showCounts is a boolean that indicates whether fields that are dynamic counters should be selectable. The default is true.
showDynamic is a boolean that indicates whether fields that can have dynamic selectors should show these as options. The default is false.
returns an input field appropriate for the field. If $field is empty, returns an empty string. If the field doesn't exist, returns undef. if field is not selectable, returns an empty string.
$status = $rfields->hRules(field, pattern [, isCaseSensitive [, isRE]]) ;
field is the field to set up rules for.
pattern is the pattern to highlight.
isCaseSensitive indicates the pattern is case sensitive (defaults to no).
isRE indicates the pattern is a regular expression (defaults to no).
Returns 1 if successful, 0 if it failed for some reason, and undef if the field does not exist.
@list = $rfields->flist();
@sFlist = $rfields->sortedFlist() ;
Returns a list of field names that are sorted by field label case insensitively.
@slist = $rfields->graphableList( menuOnly [, prefix [, sort ] ] ) ;
menuOnly is a flag that indicates only menu fields should be included in the list. It defaults to false.
prefix is an optional string to attach to the front of the fieldnames.
sort is a flag that indicates the returned list should be sorted by field label. The default is true.
Returns a list of fields that are not hidden and are marked as graphable.
$newval = $rfields->makeValid($field, $value);
returns a valid value, which may have been reordered if it is a list field.
@fList = $rfields->nameParts() ;
Returns an ordered list of the fields that should be used in the displayID of the requirement.
$num = $rfields->numFields();
returns the number of fields defined in a schema
$rfields->print(); $rfields->print(field);
returns the string-ified version of the entire database, or just the contents of field
Really a no-op, since this object does not have a database.
$desc = $rfields->selDesc(field, selRef, noShowName, updateDynamic ) ;
field is the name of the field.
selRef is a hash reference to a selector.
noShowName is a boolean. If true, the field name is suppressed. Defaults to false.
updateDynamic is a boolean. If true, dynamic selectors will have their values refreshed before the description is produced. Defaults to true.
Returns a string that is a description of the selection in the context of the field type.
@slist = $rfields->selectableList( menuOnly [, prefix [, sort ] ] ) ;
menuOnly is a flag that indicates only menu fields should be included in the list. It defaults to false.
prefix is an optional string to attach to the front of the fieldnames.
sort is a flag that indicates the returned list should be sorted by field label. The default is true.
Returns a list of fields that are not hidden and are marked as selectable.
Gets/sets a handle to a test session from which variables can be extracted and interpolated into field values during formatting.
$val = $rfields->sessVars(vname) ;
Returns the value of the session variable, or undef if the variale is not defined for the session. Also returns undef if the schema object does not have a sessionVarHandle.
$dir = $rfields->suiteDir(); $rfields->suiteDir(suite);
Gets/sets the path to the test suite data root.
@tlist = $rfields->tables() ;
$type = $rfields->typeOf(name);
searches the schema for a field with the given name. Returns the type of that field as a string.
@list = $rfields->valueAsList(fieldName, value) ;
Returns a list that contains all the discrete values from 'value' when interpreted as a field named fieldName. If fieldName is in a table, then appropriate unescaping is done first.
In a scalar context, returns a reference to the list.
@values = $rfields->valuesOf(name);
searches the schema for a field with the given name. Returns an array of legal values for that field.
@list = $rfields->visibleList() ;
my $status = $rfields->write() ;
Updates the requirement field file for the current suite / profile with the current state of the requirement fields.
Returns 1 on success, 0 on failure.
my $text = $rfields->serialize() ;
Returns a text representation of the object, suitable for saving.
$ref = $rfields->idField ( [ $ref ] ) ;
ref is an optional reference to an ID field object. If supplied, that ref is used to update the idField.
Returns the reference to the idField, or undef if there is no field of type id.
$rfields->inHistory(name);
searches the schema for a field with the given name. Returns true if that field is in a history table.
$rfields->inTable(name);
searches the schema for a field with the given name. Returns true if that field is in a table.
$rfields->isBulkEditable(name) ;
searches the schema for a field with the given name. Returns true if that field should be not bulk editable.
$rfields->isHidden(name);
searches the schema for a field with the given name. Returns true if that field should be not displayed.
my $field = $schema->historyTable();
Returns the name of the field that contains the history table definition.
If there is no historyTable, returns undef.
my $size = $schema->tableSize(tableName, reqReference);
tableName - the name of a table field.
reqReference - a reference to a requirement object.
Returns the number of rows the table will require. Returns undef if the field is not a table field, does not exist, or has no fields.
my $field = $schema->historyTextarea();
Returns the name of the field to put automated revision history entries in.
Chooses the atm_mcomments field if present, and in a history table, otherwise the first textarea in a history table.
Returns undef if no field matches.
$rfields->isGraphable(name);
searches the schema for a field with the given name. Returns true if the field is graphable, or false if it is not.
$rfields->isList(name);
searches the schema for a field with the given name. Returns true if that field is a list type field.
$rfields->styleOf(name);
searches the schema for a field with the given name. Returns the style of that field as a string.
$rfields->labelOf(name [, includeMarkers] );
searches the schema for a field with the given name. Returns the label of that field as a string. if includeMarkers is true, also annotates the label with mandatory and namepart markers.
$rfields->isNamepart(field)
Searches the requirement fields for a field named field. Returns true if the field is a namepart, or false if it is not.
$rfields->isNumber(field)
Searches the requirement fields for a field named field. Returns true if the field has a numeric style, or false if it does not.
$rfields->isOutline()
Returns true if the requirements are using outline numbering mode, and false if not. Returns undef if there is no ID field (which is, of course, impossible).
$rfields->isSelectable(name);
searches the schema for a field with the given name. Returns true if the field is selectable, or false if it is not.
$rfields->isVisible(name);
searches the schema for a field with the given name. Returns true if the field is visible in reports.
$rfields->getFieldsByType(type[,style]);
searches the schema for fields of a given type, and optionally a given style. Returns a list of field names.
Returns JavaScript code that defines the dependencies among schema fields for use in the schema editor and also in selector pages.
my $tname = $rfields->SQL_tname ;
my $val = $field->SQL_value($val) ;
Returns the value of the field after interpretation by TestDB object.
$field = new ReqFields::Field(hash);
Creates a new Field object and associates its attributes with the object.
a hash of field attributes
returns a reference to the Field object.
$name = $field->name();
$field->isBulkEditable();
$field->cantSelect();
$field->canSearch();
$default = $field->default();
@descs = $field->descs();
$desc = $field->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.
$flags = $field->getFlags();
Returns a value for the FLAGS field of a SCHEMA2 file.
$field->hidden();
If there are hRules defined for the field, highlight the data that matches those rules.
$output = $field->highlight($input) ;
input is a string to highlight.
Output is returned with any matching data highlighted.
If there are hRules defined for the field, mark the data that matches those rules, ready for doHighlight() later.
$output = $field->highlight( input, displayStr );
input is a string to highlight.
if displayStr is specified, then if input matches a rule, display displayStr instead, highlighted. This is used for menu fields.
Returns input (or displayStr, where appropriate) with matching areas bounded by \03 and \04.
$output = $field->doHighlight( value );
value is the string to process.
Returns value, after replacing \03 and \04 (inserted by prepHighlight) with HTML for applying highlighting.
If the field is markup, doHighlight also escapes the markup so the field is displayed "as is".
$graphable = $field->graphable();
$status = $field->hRules(pattern [, isCaseSensitive [, isRE]]) ;
pattern is the pattern to highlight.
isCaseSensitive indicates the pattern is case sensitive (defaults to no).
isRE indicates the pattern is a regular expression (defaults to no).
Returns 1 if successful, 0 if it failed for some reason.
$field->inHistory( [ fname ] );
fname - the name of the field.
$field->inTable( [ fname ] );
fname - the name of the field.
$field->isDate() ;
Returns 1 if the field is date only, 2 if it is a date/time field, and 0 if it is neither.
$field->isList();
$field->isNumber();
Note that there are a number of numeric "styles".
$field->isRange();
$field->isMarkup();
$field->isTable();
$field->isText();
$field->isImportable();
Returns false for table fields, and any built-in fields marked as not importable, and true for anything else.
$label = $field->label();
$selectable = $field->selectable();
$searchable = $field->searchable();
$field->fixFlags() ;
Returns nothing.
$field->setFlags(flags);
Returns nothing
$size = $field->size(size);
Returns the current size of the field.
$size = $field->sizeAsHtml(limit);
returns a string suitable for use in the appropriate input element.
$type = $field->type();
$importable = $field->importable();
$prompt = $field->prompt();
$mapRef = $field->valMap() ;
Returns a reference to a hash that maps descriptions to values. Caches the map so that subsequent lookups are faster.
$val = $field->valueOf($desc) ;
desc is the value to describe.
Returns the associated value if the variable is a list. If desc if a reference to an array, then returns a reference to an array of descriptions.
@vlist = $field->values();
@vlist = $field->valuesList( [ $lRef ] ) ;
lRef is an optional reference to a list of values. If supplied, the stored list of values will be updated.
Returns a list of values.
$style = $field->style();
$visible = $field->visible();
Really a no-op, since this object does not have a database.
$value = $field->WHATEVER(); $value = $field->WHATEVER(newvalue);
Updates the setting of the WHATEVER attribute. Returns the current or new setting.
Copyright © 2000-2013 Applied Testing and Technology, Inc. All rights reserved.