Form::Factory::Feature::Role::Control - Form features tied to particular controls
version 0.008
package MyApp::Feature::Control::Color; use Moose; with qw( Form::Factory::Feature Form::Factory::Feature::Role::Check Form::Factory::Feature::Role::Control Form::Factory::Feature::Role::CustomControlMessage ); 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 { 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 }; } package Form::Factory::Feature::Control::Custom::Color; sub register_implementation { 'MyApp::Feature::Control::Color' }
And then used in an action via:
package MyApp::Action::Foo; 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 ) ], }, }, );
This role is required for any feature attached directly to a control using has_control.
has_control
This is the control object the feature has been attached to.
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.