[Catalyst] HTML::FormHandler and the Catalyst stash

Jacinta jarich at perltraining.com.au
Wed Jan 16 10:39:18 GMT 2013

G'day folk,

I've been working through the Catalyst tutorial (again) and I decided to =

give HTML::FormHandler a go.  It's tutorial at =

ndler/Manual/Tutorial.pod =

has been great.

However I am stuck on something I am certain should be easy, but is not =

proving so...

As per the tutorial my edit method looks much like this:

    sub edit : Local {
         my ( $self, $c, $book_id ) =3D @_;

         $c->stash( template =3D> 'books/edit.tt2',
                    form =3D> $self->form );

         # Validate and insert/update database
         return unless $self->form->process( item_id =3D> $book_id,
            params =3D> $c->req->parameters,
            schema =3D> $c->model('DB')->schema );

         # Form validated, return to the books list
         $c->flash->{status_msg} =3D 'Book saved';

and that works beautifully.  However, I've enhanced my examples as I've =

gone along and instead of going to the list of books, I want to go to my =

review page and print out all of the details (including extra stuff) of =

this specific book I've just added.

So I would like to change the last line to be:

    $c->res->redirect($c->uri_for($self->action_for('review'), [$book_id]));

This works perfectly if I'm editing a book, but if I'm creating a book =

for the first time, $book_id is undefined so I pass in an undefined id =

to review.  Review seems to deal with that okay:

    sub review :Chained('object') :PathPart('review') :Args(0) {
         my ($self, $c) =3D @_;

        my $book =3D $c->stash->{object};


until I want to use $book for something.

I have looked through most of the documentation for HTML::FormHandler =

and I can't find anything that actually documents process() (it returns =

1 on success) and I don't know the Catalyst stash well enough.  Is this =

information hiding therein or do I need to create a method to get the =

last insert id?

All help gratefully appreciated.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20130116/3f1f0=

More information about the Catalyst mailing list