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

NAME

Form::Factory::Processor - Moos-ish helper for action classes

VERSION

version 0.001

SYNOPSIS

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


  use Form::Factory::Processor;

  has_control name => (
      control => 'text',
      options => {
          label => 'Your Name',
      },
      features => {
          trim     => 1,
          required => 1,
          length   => {
              minimum => 3,
              maximum => 15,
          },
      },
  );

  has_cleaner convert_to_underscores => sub {
      my $self = shift;
      my $name = $self->controls->{name}->current_value;
      $name =~ s/\W+/_/g;
      $self->controls->{name}->current_value($name);
  };

  has_checker do_not_car_for_names_start_with_r => sub {
      my $self = shift;
      my $value = $self->controls->{name}->current_value;

      $self->error('i do not like names start with "R," get a new name')
          if $value =~ /^R/i;
  };

  has_pre_processor log_start => sub {
      my $self = shift;
      MyApp->logger->debug("START Foo " . Time::HiRes::time());
  };

  has_post_processor log_stop => sub {
      my $self = shift;
      MyApp->logger->debug("STOP Foo " . Time::HiRes::time());
  };

  sub run {
      my $self = shift;
      MyApp->do_something_to_your_name($self->name);
  }

DESCRIPTION

This is the helper class used to define actions. This class automatically imports the subroutines described in this documentaiton as well as any defined in Moose. It also grants your action class and its meta-class the correct roles.

METHODS

init_meta

Sets up the roles and meta-class information for your action class.

has_control

  has_control $name => (
      %usual_has_options,

      control  => $control_short_name,
      options  => \%control_options,
      features => \%control_features,
  );

This works very similar to "has" in Moose. This also applies the Form::Factory::Action::Meta::Attribute::Control trait to the attribute and sets up other defaults.

The following defaults are set:

is

Control attributes are read-only by default.

isa

Control attributes are string by default. Be careful about using an isa setting that differs from the control's value. If you do, make sure you use features to make certain the type is the correct kind of thing or that a coercion to the correct type of thing is also setup.

control

This will default to "text" if not set.

options

An empty hash reference is used by default.

features

An empty hash references is used by default.

deferred_value

  has_control publish_on => (
      control => 'text',
      options => {
          default_value => deferred_value {
              my ($action, $control_name) = @_;
              DateTime->now->iso8601,
          },
      },
  );

This is a helper for deferring the calculation of a value. This works similar to Scalar::Defer to defer the calculation, but with an important difference. The subroutine is passed the action object (such as it exists while the controls are being constructed) and the control's name. The control itself doesn't exist yet when the subroutine is called.

has_cleaner

  has_cleaner $name => sub { ... }

Adds some code called during the clean phase.

has_checker

  has_checker $name => sub { ... }

Adds some code called during the check phase.

has_pre_processor

  has_pre_processor $name => sub { ... }

Adds some code called during the pre-process phase.

has_post_processor

  has_post_processor $name => sub { ... }

Adds some code called during the post-process phase.

SEE ALSO

Form::Factory::Action

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.