简体   繁体   中英

HTML::FormHandler persistent form class

I'm using HTML::FormHandler and I'd like to make my form persistent by making it a moose attribute in my controller class. In HTML::FormHandler's Manual Intro documentation , it says this:

FormHandler makes heavy use of Moose, so almost all of FormHandler's 
profiled time will actually be in Moose methods, mostly constructing form 
and field attributes. Some people prefer to use a persistent form class 
(in a Moose attribute) in order to skip the form building step on each call.

I would like to do this, however it doesn't give an example and I'm not too familiar with Moose, so I have no idea how to do this. Has anyone done this before that can give an example of what to put in your Catalyst code to accomplish this? Or just and idea of how to do it? Thanks!

So I ended up finding the solution. It turns out an example was just in a different section of documentation on how to use HTML::FormHandler with Catalyst: HTML::FormHandler::Manual::Catalyst . Here is an example on how to make a form persistent (straight from the documentation)

package MyApp::Controller::Book;
use Moose;
BEGIN { extends 'Catalyst::Controller'; }
use MyApp::Form::Book;
has 'edit_form' => ( isa => 'MyApp::Form::Book', is => 'rw',
    lazy => 1, default => sub { MyApp::Form::Book->new } );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM