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

NAME

Form::Factory::Processor::Role - Moos-ish helper for action roles

VERSION

version 0.021

SYNOPSIS

  package MyApp::Action::Role::HasAuthor;
  use Form::Factory::Processor::Role;

  has_control author => (
      control => 'text',
      features => {
          trim => 1,
          required => 1,
      },
  );

  has_checker authors_should_be_proper_names => (
      my $self = shift;
      my $value = $self->controls->{author}->current_value;

      # We want two words, but only a warning since I have a friend with only
      # one name... we wouldn't want to discriminate.
      $self->warning('you really should use a full name')
          if $value !~ /\w\s+\w/;
      $self->result->is_valid(1);
  );

  package MyApp::Action::Post;
  use Form::Factory::Processor;

  with qw( MyApp::Action::Role::HasAuthor );

  has_control title => (
      control => 'text',
      features => {
          trim => 1,
          required => 1,
      },
  );

  has_control body => (
      control => 'full_text',
      features => {
          trim => 1,
          required => 1,
      },
  );

  sub run {
      my $self = shift;

      my $filename = $self->title . '.txt';
      $filename =~ s/\W+/-/g;

      open my $fh, '>', $filename or die "cannot open $filename: $!";
      print $fh "Title: ", $self->title, "\n";
      print $fh "Author: ", $self->author, "\n";
      print $fh "Body: ", $self->body, "\n";
      close $fh;
  }

DESCRIPTION

This is a helper class used to define action roles. This class automatically imports the subroutiens described in this documentation as well as any defined in Moose::Role.

You may compose roles defined this way to build a complete action.

METHODS

init_meta

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

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::Role. This applies the Form::Factory::Action::Meta::Attribute::Control trait to the attribute and sets up other defaults. These defaults match those shown in "has_control" in Form::Factory::Processor.

use_feature

This function is used to make an action role use a particular form feature. You use it like this:

  use_feature $name => \%options;

The %options are optional. So, this is also acceptable:

  use_feature $name;

The $name is a short name for the feature class. For example, the name "require_none_or_all" will load teh feature defined in Form::Factory::Features::RequireNoneOrAll.

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::Role

AUTHOR

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2010 Qubling Software LLC.

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