Catalyst::Model::FormFu

Catalyst::Model::FormFu has just hit CPAN. It is an experimental alternative interface to HTML::FormFu for Catalyst and its main puprpose is to provide improved performance over the existing Catalyst::Controller::HTML::FormFu. It parses the form configuration files and loads form objects during application startup, and then returns clones of these objects inside your actions. It is hard to evaluate precisely the performance boost that this provides (disk access speed will vary, and there is always the Catalyst overhead), but my crude benchmarks indicate that you can expect a form object to be loaded at least twice as fast when using Catalyst::Model::FormFu.

Additionally, since Catalyst::Model::FormFu does not inherit from Catalyst::Controller, it can be used with Catalyst::Controller::ActionRole - a feature many users have requested. Also, you can easily work with more than one form object inside a single action, which was there was no straightforward way to do before.

The configuration options are very simialar to those of Catalyst::Controller::HTML::FormFu, except that you must also specify a hash of forms whose values are the configuration files corresponding to each form, e.g.:

<Model::FormFu>
    <constructor>
        config_file_path "myapp/root/forms"
    </constructor>
    <model_stash>
        schema Books
    </model_stash>
    <forms>
        book book.conf
        author author.conf
    </forms>
</Model::FormFu>

You can then access form objects like this:

sub edit :Local
{
    my ($self, $c, @args) = @_;
    my $book = $c->model('FormFu')->form('book');
    if ($book->submitted_and_valid)
    ...
}
Posted in Modules
blog comments powered by Disqus