The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Form::Factory::Feature::Role::Control - Form features tied to particular controls

VERSION

version 0.002

SYNOPSIS

  package Form::Factory::Feature::Control::Color;
our $VERSION = '0.002';


  use Moose;

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

  has recognized_colors => (
      is        => 'ro',
      isa       => 'ArrayRef[Str]',
      required  => 1,
      default   => sub { [ qw( red orange yellow green blue purple black white ) ] },
  );

  sub check_control {
      my ($self, $control) = @_;

      die "color feature is only for scalar valued controls"
          unless $control->does('Form::Factory::Control::Role::ScalarValue');
  }

  sub check_value {
      my $self  = shift;
      my $value = $self->control->current_value;

      $self->control_error('the %s does not look like a color')
          unless grep { $value eq $_ } @{ $self->recognized_colors };
  }

And then used in an action via:

  package MyApp::Action::Foo;
our $VERSION = '0.002';


  use Form::Factory::Processor;

  has_control favorite_primary_color => (
      control  => 'select_one',
      options  => {
          available_choices => [
              map { Form::Factory::Control::Choice->new($_, ucfirst $_) }
                qw( red yellow blue )
          ],
      },
      features => {
          color => {
              recognized_colors => [ qw( red yellow blue ) ],
          },
      },
  );

DESCRIPTION

This role is required for any feature attached directly to a control using has_control.

ATTRIBUTES

control

This is the control object the feature has been attached to.

METHODS

clean

Checks to see if a clean_value method is defined and calls it if it is.

check

Checks to see if a check_value method is defined and calls it if it is.

pre_process

Checks to see if a pre_process_value method is deifned and calls it if it is.

post_process

Checks to see if a post_process_value method is deifned an calls it if it is.

format_message

  my $formatted_message = $feature->format_message($unformatted_message);

Given a message containing a single %s placeholder, it fills that placeholder with the control's label. If the control does not implement Form::Factory::Control::Role::Labeled, the control's name is used instead.

control_info

Reports an informational message automatically filtered through "format_message".

control_warning

Reports a warning automatically filtered through "format_message".

control_error

Reports an error automatically filtered through "format_error".

AUTHOR

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2009 Qubling Software LLC.

This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.