CheckValue.pm


NAME

Communiware::CheckValue - unified value tester.


SYNOPSIS

        use Communiware::CheckValue qw(check_value)
        check_value($value, %opts)


DESCRIPTION

The function check_value exported by this module performs various checks of given value. It can be called at compile or run time - from some DE compilator or executor.

The set on neede checks as well as error reaction are defined by options.

Options

name=value_name
Gives a value name, this name will be used in error messages. Otherwise the word value will be used.

frag=$frag
Reference to Communiware::Template::Fragment object. If this option is given then it is compile time, runtime otherwise. The way of error messaging depends on this option too. In compile time $frag->compile_error is used, or it dies otherwise.

mustbeconst=bool
True value of this option requires that value was constant at compile time.

mustdef=bool
If true then value must be defined.

filter=bool
True value of this option tells that value must be a true filter expression. check_value performs validate_filter if it can recognize filter expression at compile time. @ATTR counts as valid filter expression.

posting=bool
If true then value is counted as non-constant if it contains non-escaped percent sign.

regexp=regexp
Value must confirm given perl regular expression.

oneof=[qw/list of values/]
Value must be one of elements in given array.

tabledomain=[qw/tablename columnname/]
Value must be one of existing columnnames in the table tablename (plus values given in oneof option).

sqldomain=``select column from table''
Value must be one of values returned in the first column of this sql-query result.

vp=bool
If the option is given and is false then checked value cannot have virtual page form, it means it cannot have an asterisk as a first character.

type=item_type
type=*
Value must be id of existing item or virtual page of any type if option value is '*' or only given type if option value is name of some item type.

tpltype=template_type
If this option is given value must be an item id (or virtual page name) of TEMPLATE type, and this template (or virtual page) must have given TEMPLATE_TYPE, for example PAGE, ELEMENT etc. Argument of this option may be array reference. In this case TEMPLATE_TYPE must be one of elements in this array.

check=sub {}
Value of this option is subroutine reference which is called vith one argument - checked value. The subroutine can perform any checks and must perform die on case of errors.


EXAMPLES

        check_value(
                $item,
                name    => 'item',
                frag    => $frag,
                posting => 1,
                mustdef => 1,
                type    => '*'
        );

The value must be id of any existing item.

        check_value(
                $o{period},
                name        => 'period',
                frag        => $frag,
                posting     => 1,
                oneof       => ['NEVER'],
                tabledomain => [qw/subscription_period period/],
        );

The value must be 'NEVER' or one of 'period's in 'subcripption_period' table.


BUGS

It will be better to use Exceptions instead of diyng at runtime.

16 октябрь 2007 13:44