NAME
Form::Factory::Control::Role::Value - controls with values
VERSION
version 0.011
DESCRIPTION
This flags a control as having a value. This may belong in Form::Factory::Control directly, but for now it is here.
ATTRIBUTES
value
This is the value set on the control. It is generally the value that "current_value" gets or sets.
METHODS
set_attribute_value
$control->set_attribute_value($action, $attribute);
Sets the value of the action attribute with current value of teh control.
ROLE METHODS
current_value
my $value = $control->current_value;
$control->current_value($new_value);
The current_value
method is an accessor and mutator for values on the control. This is different from the "value" attribute as other attributes or values may be involved in determining what the current value is. For example, a text
control defines the current_value
something like this:
sub current_value {
my $self = shift;
if (@_) {
$self->value(@_);
}
return $self->has_value ? $self->value
: $self->has_default_value ? $self->default_value
: ''
;
}
The value will change if set, but the default_value
attribute is used if available and it will fall back to an empty string failing that.
has_current_value
All value controls must also define a has_current_value
method. This is used to determine if the control has a current value. This should be a little more robust than a simple check on whether the current_value
is defined, though. Rather, it should check if this is a useful value.
Typically, in forms, an empty string submitted indicates a blank value rather than a useful value. That is, it may be defined, but it's not valuable.
This method is only given the control object as it's parameter and the return value is a boolean indicating whether the current value is useful.
AUTHOR
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
COPYRIGHT AND LICENSE
Copyright 2009 Qubling Software LLC.
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.