The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

HTML::Tested::Value - Base class for most HTML::Tested widgets.

DESCRIPTION

This class provides the most basic HTML::Tested widget - simple value to be output in the template.

METHODS

$class->new($parent, $name, %opts)

Creates new HTML::Tested::Value named $name at parent class $parent.

%opts is a hash containing various options changing behaviour of this widget.

See OPTIONS section for description of available options.

$widget->name

Returns the name of the widget.

$widget->options

Returns hash of options assigned to this widget. See OPTIONS section for description of available options.

$widget->value_to_string($name, $val, $caller, $stash)

This function is called from render to return final string which will be rendered into stash. For HTML::Tested::Value it simply returns $val.

$caller is the object calling this function. $stash is read-only hash of the values accummulated so far.

$widget->encode_value($val)

Uses HTML::Entities to encode $val.

$widget->get_value($caller, $id)

It is called from $widget->render to get the value to render. If the value is undef get_default_value will be used to get default value for the widget.

$widget->seal_value($value, $caller)

If is_sealed option is used, this function is called from $widget->render to seal the value before putting it to stash. See HTML::Tested::Seal for sealing description.

This function maintains cache of sealed values in caller. Thus promising that the same value will map to the same id during request.

$widget->render($caller, $stash, $id, $name)

Renders widget into $stash. For HTML::Tested::Value it essentially means assigning $stash->{ $name } with $widget->get_value.

$widget->push_constraint($constraint)

$constraint should be ARRAY reference with the following format:

[ TYPE, OP, COOKIE ]

where TYPE is type of the constraint, OP is the operation to be done on the constraint and cookie is optional method for the application to recognize specific constraint.

Available types are:

regexp

With OP being regexp string (or qr// value) (e.g. [ regexp => '\d+' ] or [ regexp => qr/\d+/ ]).

defined

Ensures that the value is defined. OP doesn't matter here (e.g. [ defined => '' ]).

any user-defined string

Any user defined constraint - second parameter should be function to call. It gets the value and the caller as the arguments.

For example [ 'my_foo' => sub { my ($v, $caller) = @_; return is_ok? } ].

$widget->validate($value, $caller)

Validate value returning list of failed constraints in the format specified above.

I.e. the $value is "constraint-clean" when validate returns empty list.

Validate is disabled if no_validate widget option is set.

$widget->absorb_one_value($parent, $val, @path)

Parses $val and puts the result into $parent object. @path is used for widgets aggregating other widgets (such as HTML::Tested::List).

OPTIONS

Options can be used to customize widget behaviour. Each widget is free to define its own options. They can be set per class or per object using ht_set_widget_option. The options can be retrieved using ht_get_widget_option.

HTML::Tested::Value defines the following options:

is_sealed

The widget value is encrypted before rendering it. The value is decrypted from the request parameters in transparent fashion.

is_disabled

The widget is disabled: it is rendered as blank value.

default_value

Default value for the widget. It is rendered if current widget value is undef.

skip_undef

Normally, if widget value is undef, the widget is rendered as blank value. When this option is set the widget will not appear in the stash at all.

constraints

Array reference containing widget value constraints. See push_constraint documentation for the individual entry format.

is_trusted

Do not perform the escaping of special characters on the value. Improperly setting this option may result in XSS security breach.

is_integer

Ensures that the value is integer.

AUTHOR

Boris Sukholitko (boriss@gmail.com)

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO

HTML::Tested