NAME
Form::Factory::Control - high-level API for working with form controls
VERSION
version 0.022
SYNOPSIS
package MyApp::Control::Slider;
use Moose;
with qw(
Form::Feature::Control
Form::Feature::Control::Role::ScalarValue
);
has minimum_value => (
is => 'rw',
isa => 'Num',
required => 1,
default => 0,
);
has maximum_value => (
is => 'rw',
isa => 'Num',
required => 1,
default => 100,
);
has value => (
is => 'rw',
isa => 'Num',
required => 1,
default => 50,
);
sub current_value {
my $self = shift
if (@_) { $self->value(shift) }
return $self->value;
}
package Form::Factory::Control::Custom::Slider;
sub register_implementation { 'MyApp::Control::Slider' }
DESCRIPTION
Allows for high level processing, validation, filtering, etc. of form control information.
ATTRIBUTES
action
This is the action to which the control is attached. This is a weak reference to prevent memory leaks.
name
This is the base name for the control.
documentation
This holds a copy the documentation attribute of the original meta attribute.
features
This is the list of Form::Factory::Feature::Role::Control features associated with the control.
value
This is the value of the control. This attribute provides a has_value
predicate. See "current_value".
default_value
This is the default or fallback value for the control used when "value" is not set. This attribute provides a has_default_value
predicate. See "current_value".
control_to_value
This may be a method name or a code reference that can be run in order to coerce the control's current value to the action attribute's value during action processing. The given method or subroutine will always be called with 3 arguments:
The action object the control has been attached to.
The control object we are converting from.
The current value of the control.
The method or subroutien should return the converted value.
This attribute provides a has_control_to_value
predicate.
value_to_control
This is either a method name (to be called on the action the control is connected with) to a code reference. This method or subroutine will be called to conver the action attribute value to the control's value.
The method or subroutine will always be called with three arguments:
The action object the control belongs to.
The control object that will receive the value.
The value of the attribute that is being assigned to the control.
The method or subroutine should return the converted value.
This attribute provides a has_value_to_control
predicate.
METHODS
current_value
This is the current value of the control. If "value" is set, then that is returned. If that is not set, but "defautl_value" is set, then that is returned. If neither are set, then undef
is returned.
This may also be passed a value. In which case the "value" is set and that value is returned.
has_current_value
Returns true if either value
or default_value
is set.
convert_value_to_control
Given an attribute value, convert it to a control value. This will cause any associated Form::Factory::Feature::Role::ControlValueConverter features to run and run the "value_to_control" conversion. The value to convert should be passed as the lone argument. The converted value is returned.
convert_control_to_value
Given a control value, convert it to an attribute value. This will run any Form::Factory::Feature::Role::ControlValueConverter features and the "control_to_value" conversion (if set). The value to convert should be passed as the only argument and the converted value is returned.
set_attribute_value
$control->set_attribute_value($action, $attribute);
Sets the value of the action attribute with current value of teh control.
get_feature_by_name
my $feature = $control->get_feature_by_name($name);
Given a feature name, it returns the named feature object. Returns undef
if no such feature is attached to this control.
has_feature
if ($control->has_feature($name)) {
# do something about it...
}
Returns a true value if the named feature is attached to this control. Returns false otherwise.
AUTHOR
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by Qubling Software LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.