Form::Factory::Processor - Moos-ish helper for action classes
version 0.005
package MyApp::Action::Foo; our $VERSION = '0.005'; 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); }
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.
Sets up the roles and meta-class information for your action class.
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:
Control attributes are read-only by default.
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.
isa
This will default to "text" if not set.
An empty hash reference is used by default.
An empty hash references is used by default.
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 $name => sub { ... }
Adds some code called during the clean phase.
has_checker $name => sub { ... }
Adds some code called during the check phase.
has_pre_processor $name => sub { ... }
Adds some code called during the pre-process phase.
has_post_processor $name => sub { ... }
Adds some code called during the post-process phase.
Form::Factory::Action
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
<hanenkamp@cpan.org>
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.
To install Form::Factory, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Form::Factory
CPAN shell
perl -MCPAN -e shell install Form::Factory
For more information on module installation, please visit the detailed CPAN module installation guide.