# Fields reference

Triceps::Fields is a package with a set of functions that help with handling the variable sets of fields in the templates.

    @fields = &Triceps::Fields::filter(
    	$caller, \@inFields, \@translation);

Filters and renames the incoming set of fields from

    \@inFields

(usually coming from some row type) according to

    \@translation

. Returns the array of filtered names, positionally matching the names in the original array. When some field gets thrown away by filtering, its entry in the array will be

    undef

. Confesses on errors.

    $caller

is the caller's description for the error messages.

See the description of the translation format in &xrsp;.

The option-processing functions

    Opt::drop()

and

    Opt::dropExcept()

can also be used to filter the field lists.

    @pairs = &Triceps::Fields::filterToPairs(
    	$caller, \@inFields, \@translation);

Performs the same actions as

    filter()

but returns the result in a different format: an array of pairs of field names, where the old field name is paired with the new one. The field names that gets thrown away by filtering do not appear in the result array.

    ($rowType, $projectFunc) = &Triceps::Fields::makeTranslation(
    	$optName => $optValue, ...);

Generates and compiles a function that performs the filtering of rows and creates the rows of the filtered type (a projection in SQL terms). It accepts multiple input row types, each with its own translation specification, and creates the result row type by combining them all. Returns two elements: the result row type and the reference to the compiled function. The function can then be called to perform the projection and combining of the original rows:

    $resultRow = &$projectFunc($origRow1, $origRow2, ..., $origRowN);

If some of the original rows are not available, they may be passed as

    undef

. The options are:

    rowTypes => [ @rts ]

  Reference to an array of row types for the original rows.

    filterPairs => [ @pairs ]

  Reference to an array of arrays returned by

      filterPairs()

  for the original rows. Obviously, each of the original rows requires its own filter. The sizes of rowTypes and filterPairs arrays must match. The field names in the results must not have any duplicates.

    saveCodeTo => \$code

  Optional. Reference to a scalar where to save the auto-generated source code of the projection function, for debugging.

    $result = &Triceps::Fields::isArrayType($typeName);

Checks whether a simple type is represented in Perl as an array. Since

    uint8[]

is represented as a string, it will return 0.

    $result = &Triceps::Fields::isStringType($typeName);

Checks whether a simple type is represented in Perl as a string.

    string

,

    uint8

and

    uint8[]

will return 1.
Fields