NAME

Form::Factory::Feature::Role::ControlValueConverter - form features that convert values

VERSION

version 0.022

SYNOPSIS

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;
}

DESCRIPTION

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.

ROLE METHODS

The feature implementing this role must provide these methods.

control_to_value

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_to_control

This method does the reverse of control_to_value and is used to convert the action attribute to the control 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.

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.