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


Form-Factory documentation Contained in the Form-Factory distribution.

Index


Code Index:

NAME

Top

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

VERSION

Top

version 0.020

SYNOPSIS

Top

  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

Top

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

Top

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

Top

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Top


Form-Factory documentation Contained in the Form-Factory distribution.
package Form::Factory::Feature::Role::ControlValueConverter;
BEGIN {
  $Form::Factory::Feature::Role::ControlValueConverter::VERSION = '0.020';
}
use Moose::Role;

with qw( Form::Factory::Feature::Role::Control );

requires qw( value_to_control control_to_value );

1;