Form::Factory::Feature::Role::Check - features that check control values


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

Index


Code Index:

NAME

Top

Form::Factory::Feature::Role::Check - features that check control values

VERSION

Top

version 0.020

SYNOPSIS

Top

  package MyApp::Feature::Bar;
  use Moose;

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

  sub check {
      my $self = shift;

      # Check the value for errors, it must contain Bar
      my $value = $self->control->{something}->current_value;
      unless ($value =~ /\bBar\b/) {
          $self->result->error('control must contain Bar');
          $self->result->is_valid(0);
      }
      else {
          $self->result->is_valid(1);
      }
  }

  package Form::Factory::Feature::Custom::Bar;
  sub register_implementation { 'MyApp::Feature::Bar' }

DESCRIPTION

Top

Features that check the correctness of control values implement this role. This runs after input has been consumed and cleaned and before it is processed. The check here is meant to verify whether the input is valid and ready for processing. Mark the result as invalid to prevent processing. In general, it's a good idea to return an error if you do that. This is also a good place to return warnings.

ROLE METHODS

Top

check

The check method is run after the data has been cleaned up and is intended for checking whether or not the data given is ready to be processed. A feature checking the input for valdation should set the is_valid flag on the result. If you do not set is_valid, then you will not influence whether or not the action is considered valid and ready to move on to the processing stage.

This method is passed no arguments other than the object it is being called on. The return value is ignored. If you check method needs to output anything, it should do so through the attached result object.

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::Check;
BEGIN {
  $Form::Factory::Feature::Role::Check::VERSION = '0.020';
}
use Moose::Role;

requires qw( check );

1;