[Catalyst] CatalystX::CRUD Storage Error

Peter Karman peter at peknet.com
Fri Jul 31 13:51:25 GMT 2009

Amiri Barksdale wrote on 7/30/09 4:11 PM:
> On Tue, Jul 28, 2009 at 08:30:44AM -0500, Peter Karman wrote:
> | Peter Karman wrote on 07/28/2009 07:51 AM:
> | >Amiri Barksdale wrote on 7/27/09 8:46 PM:
> | >>On Thu, Jul 16, 2009 at 11:33:38PM -0500, Peter Karman wrote:
> | >>| Also, your controller inherits from the base CatalystX::CRUD::Controller, which
> | >>| doesn't really *do* anything by default. I.e., you need a form handler to
> | >>| serialize and validate your model. Look at CatalystX::CRUD::Controller::RHTMLO
> | >>| for one example. Or consider writing a controller base class that adapts your
> | >>| favorite form handler (HTML::FormFu or Form::Processor or ...).
> This is what I am trying to do. I have been poring over the docs for
> CatalystX::CRUD::Controller::RHTMLO, and looking at its source code, to
> see whether I can figure out what adaptations to make to tie FormHandler
> to C:X:CRUD. I am just unclear on the API I think.
> Is this correct: To make a controller base class to use
> HTML::FormHandler with C:X:CRUD, I can look at, for instance,
> CatalystX::CRUD::Controller::RHTMLO, and just replicate its
> functionality using Formhanlder stuff? I need subroutines named
> form, field_names, all_form_errors, form_to_object, do_search, etc.,
> because those are what CatalystX::CRUD::Controller expects?

You probably don't need all those. At a minimum:


I've just read over the pod for HTML::FormHandler for the first time, so take my
remarks as those of a complete novice in that regard. But here are some first
attempts you could play with and modify. I think creating a generalized
CX::C::C::HFH class will be a little tricky since the model support is already
baked into HFH, but it could be made to work, I'm sure, by someone more familiar
with the workings of HFH.

as an example:

sub form {
    my ( $self, $c ) = @_;
    $self->throw_error("context required") unless defined $c;
    $self->{_form} ||= $self->form_class->new;
    $self->{_form}->ctx($c);  # $c should be weaken()'d
    return $self->{_form};

sub field_names {
    my ( $self, $c ) = @_;
    $self->throw_error("context required") unless defined $c;
    return [ map { $_->name } @{ $self->form($c)->fields } ];

# this is usually the heart of a CX::C::Controller
# but see comments on process() below.
sub form_to_object {
    my ( $self, $c ) = @_;
    return $c->stash->{object}; # basically a no-op

sub save_obj {
    my ( $self, $c ) = @_;

# here's where H::F is unique,
# since the process() method does a lot of what
# CX::C::Controller does too.
# I'm not sure how best to do this.

    my $form      = $c->stash->{form};
    my $obj       = $c->stash->{object};

# process() does mostly what save() does in CX::C::Controller
    return $form->process( item => $obj, params => $c->req->params );

Hope that steers you in the right direction. You might seek counsel from the HTH
folks as to what the best way is to use just the form handling pieces of HTH,
without the model integration, since one of the chief aims of CX::C::Controller
is to *do* the model integration for you. The code above basically delegates all
the model integration to the process() method, as HTH does.

Peter Karman  .  http://peknet.com/  .  peter at peknet.com
gpg key: 37D2 DAA6 3A13 D415 4295  3A69 448F E556 374A 34D9

More information about the Catalyst mailing list