[Catalyst] Invoke *complete* subrequests in Catalyst?

Matt S Trout dbix-class at trout.me.uk
Wed Sep 20 16:36:46 CEST 2006

Nate Wiger wrote:
> Matt S Trout wrote:
>> Nate Wiger wrote:
>>> I'm building an AJAX app with FormBuilder, and want to use it to embed 
>>> multiple forms in a page (each of which would be linked to a different 
>>> action and submitted using JQuery). I've found I can do this, but I've 
>>> had to make changes to the FB plugin so that it only instantiates an 
>>> object on a call to $c->form, and doesn't use prepare() to do so. This 
>>> then requires a bit of internal magic to work both normally and in 
>>> subrequest mode.
>>> Other ideas?
>> Actually, yes.
>> You just proved *perfectly* why this is a really stupid thing to have as a 
>> plugin ...
> Never said I wasn't going to do that... but it doesn't really solve the 
> problem. I've played with the base class, AFAICT it has the issue that 
> you have to say something like this:
>     sub myform : Local Form {
>         my($self,$c) = @_;
>         my $form = $c->form;
>         $form->etc(...);
>         $c->stash->{form_output} = $form->render;
>     }
> To get the form instantiated and rendered. In the normal case, having it 
> as a plugin makes sense because:
>     - The form config is automatically resolved per the $c->action
>     - The form is loaded during Catalyst preparation
>     - The form is rendered automatically via Catalyst View::Whatever

So in your controller base class include an _parse_Form_attr method that sets 
it up as :ActionClass('+Catalyst::Controller::FormBuilder::Action') or similar.

Then that custom action class can wrap the execute phase and do any setup 
based on $c->action required.

This also has the advantage of potentially allowing more than one form later.

> I'm not sure if you've actually tried to use the FormBuilder plugin or 
> not. If you can show/hint/link at how these items could be done via a 
> base class, and auto-invoked during prepare(), that would be helpful. So 
> far I can't find any decent documentation on controller base classes.

Best bet is to have a read of Catalyst::Base and see how it does stuff.

      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +

More information about the Catalyst mailing list