Form::Factory::Feature::Role::ControlValueConverter - form features that convert values
version 0.022
package MyApp::Feature::Control::Integer; use Moose; with qw( Form::Factory::Feature Form::Factory::Feature::Role::ControlValueConverter ); sub check_control { my ($self, $cotnrol) = @_; die "not a scalar valued control" unless $control->does('Form::Factory::Control::Role::ScalarValue'); } sub control_to_value { my ($self, $value) = @_; return int($value); } sub value_to_control { my ($self, $value) = @_; return ''.$value; }
This role is used to provide standard value convertions between control values and action attributes. This allows you to reuse a common conversion by creating a feature to handle it.
Use of this role implies Form::Factory::Feature::Role::Control.
The feature implementing this role must provide these methods.
This method is used to convert a value on a control for use in assignment to the action attribute to which it is attached.
This method should be defined like so:
sub control_to_value { my ($self, $value) = @_; return # ... converted value ... }
The $value here will be teh value to convert. This is usually going to be the current_value of the control, but might be something else, so make sure you use the given value for conversion.
$value
current_value
This method does the reverse of control_to_value and is used to convert the action attribute to the control value.
control_to_value
It is defined like this:
sub value_to_control { my ($self, $value) = @_; return # ... converted value ... }
The $value here will be a value from the action attribute (or something of the same type) and the value returned should be appropriate for assigning to the control value.
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
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.
To install Form::Factory, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Form::Factory
CPAN shell
perl -MCPAN -e shell install Form::Factory
For more information on module installation, please visit the detailed CPAN module installation guide.