View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Boris Sukholitko > HTML-Tested > HTML::Tested::Value



Annotate this POD


New  2
Open  0
View/Report Bugs


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


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


$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.


Returns the name of the widget.


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.


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.


$constraint should be ARRAY reference with the following format:


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:


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


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 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:


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


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


Default value for the widget. It is rendered if current widget value is 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.


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


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


Ensures that the value is integer.


Boris Sukholitko (


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.



syntax highlighting: