Catalyst::Model::FormFu - Speedier interface to HTML::FormFu for Catalyst
version 0.004
package MyApp { use parent 'Catalyst'; __PACKAGE__->config( 'Model::FormFu' => { model_stash => { schema => 'MySchema' }, constructor => { config_file_path => 'myapp/root/forms' }, forms => { form1 => 'form1.yaml', form2 => 'form2.yaml', ] } ); } package MyApp::Controller::WithForms { use parent 'Catalyst::Controller'; sub edit :Local { my ($self, $c, @args) = @_; my $form1 = $c->model('FormFu')->form('form1'); if ($form1->submitted_and_valid) ... } } package MyApp::Model::FormFu { use parent 'Catalyst::Model::FormFu'; }
Catalyst::Model::FormFu is an alternative interface for using HTML::FormFu within Catalyst. It differs from Catalyst::Controller::HTML::FormFu in the following ways:
Catalyst::Model::FormFu
It initializes all required form objects when your app is started, and returns clones of these objects in your actions. This avoids having to call "load_config_file" in HTML::FormFu and "populate" in HTML::FormFu every time you display a form, leading to performance improvements in persistent applications.
It does not inherit from Catalyst::Controller, and so is safe to use with other modules that do so, in particular Catalyst::Controller::ActionRole.
Note that this is a completely different module from the original Catalyst::Model::FormFu by Daisuke Maki, which is now only available on the BackPAN (http://backpan.perl.org/authors/id/D/DM/DMAKI/Catalyst-Model-FormFu-0.01001.tar.gz).
Catalyst::Model::FormFu accepts the following configuration options
A hashref where keys are the names by which the forms will be accessed, and the values are the configuration files that will be loaded for the respective forms.
A hashref of options that will be passed to HTML::FormFu->new(...) for every form that is created.
HTML::FormFu->new(...)
A hashref with a stash key whose value is the name of a Catalyst model class that will be place in the form stash for use by HTML::FormFu::Model::DBIC.
stash
If true (the default), a coderef is passed to $form->config_callback->{plain_value} which replaces any instance of __uri_for(URI)__ found in form config files with the result of passing the URI argument to "uri_for" in Catalyst.
$form->config_callback->{plain_value}
__uri_for(URI)__
URI
The form __uri_for(URI, PATH, PARTS)__ is also supported, which is equivalent to $c->uri_for( 'URI', \@ARGS ). At this time, there is no way to pass query values equivalent to $c->uri_for( 'URI', \@ARGS, \%QUERY_VALUES ).
__uri_for(URI, PATH, PARTS)__
$c->uri_for( 'URI', \@ARGS )
$c->uri_for( 'URI', \@ARGS, \%QUERY_VALUES )
The second codeword that is being replaced is __path_to( @DIRS )__. Any instance is replaced with the result of passing the DIRS arguments to "path_to" in Catalyst. Don't use quotation marks as they would become part of the path.
__path_to( @DIRS )__
DIRS
If set to a true value the action for the form will be set to the currently called action name.
If set to a true value the action for the form will be set to the currently called action path.
The action path includes concurrent to action name additional parameters which were code inside the path.
Example:
action: /foo/bar called uri contains: /foo/bar/1 # default_action_use_name => 1 leads to: $form->action = /foo/bar # default_action_use_path => 1 leads to: $form->action = /foo/bar/1
To allow your form validation packages, etc, access to the catalyst context, a weakened reference of the context is copied into the form's stash.
$form->stash->{context};
This setting allows you to change the key name used in the form stash.
Default value: context
context
If you're using a L10N / I18N plugin such as Catalyst::Plugin::I18N which provides a languages method that returns a list of valid languages to use for the current request - and you want to use FormFu's built-in I18N packages, then setting "languages_from_context"
languages
If you're using a L10N / I18N plugin such as Catalyst::Plugin::I18N which provides it's own localize method, you can set localize_from_context to use that method for FormFu's localization.
localize
Use the form method of the model to fetch one or more forms by their names. The form is loaded with the current request parameters and processed.
form
Catalyst::Controller::HTML::FormFu
HTML::FormFu::Library
Peter Shangov <pshangov@yahoo.com>
This software is copyright (c) 2011 by Peter Shangov.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Catalyst::Model::FormFu, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Model::FormFu
CPAN shell
perl -MCPAN -e shell install Catalyst::Model::FormFu
For more information on module installation, please visit the detailed CPAN module installation guide.