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.
Creates new HTML::Tested::Value named $name at parent class $parent.
$name
$parent
%opts is a hash containing various options changing behaviour of this widget.
%opts
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.
This function is called from render to return final string which will be rendered into stash. For HTML::Tested::Value it simply returns $val.
render
$caller is the object calling this function. $stash is read-only hash of the values accummulated so far.
$caller
$stash
Uses HTML::Entities to encode $val.
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.
undef
get_default_value
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.
is_sealed
This function maintains cache of sealed values in caller. Thus promising that the same value will map to the same id during request.
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:
$constraint
[ 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.
TYPE
OP
Available types are:
regexp
With OP being regexp string (or qr// value) (e.g. [ regexp => '\d+' ] or [ regexp => qr/\d+/ ]).
qr//
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? } ].
Validate value returning list of failed constraints in the format specified above.
I.e. the $value is "constraint-clean" when validate returns empty list.
$value
validate
Validate is disabled if no_validate widget option is set.
no_validate
Parses $val and puts the result into $parent object. @path is used for widgets aggregating other widgets (such as HTML::Tested::List).
$val
@path
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.
ht_set_widget_option
ht_get_widget_option
HTML::Tested::Value defines the following options:
HTML::Tested::Value
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.
push_constraint
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 (boriss@gmail.com)
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.
HTML::Tested
To install HTML::Tested, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Tested
CPAN shell
perl -MCPAN -e shell install HTML::Tested
For more information on module installation, please visit the detailed CPAN module installation guide.