[Catalyst] How much chain?

Thomas Klausner domm at cpan.org
Fri Jul 11 13:09:56 BST 2008


... do I need to hang myself?

I'm (finally) playing around with chained, and like it very much.
But now I have some sort of design question, on which I'd like to 
collect some feedback:

Say, you want to edit things. The general way of editing is the same for 
most things, only the thingies you want to edit differ (i.e. their 
fields).

(slightly OT, but some background: We want to use HTML::FormFu 
for actual form generation, but do not want to use the config-file 
aproach, but something like a 'registry' where each field and it's 
definition is stored (basically we have several different things using 
similar fields...))


What to you think is better:

A) lots of chain

package Thing:
use base 'Generic';
sub base : Chained('/') PathPart('thing') CaptureArgs(0) {}
sub setup_fields : Chained('item') CaptureArgs(0) {
    # define a list of fields and store them in stash
}

package Generic;
sub item : Chained('base') PathPart('') CaptureArgs(1) {
    # load thing and store in stash
}
sub show_form : Chained('setup_fields') Args(0) {
    # take field list, make form, etc 
}

I'd end up with an URL like 
  /thing/123/setup_fields/show_form


B) Plain Old Methods

package Thing:
use base 'Generic';
sub base : Chained('/') PathPart('thing') CaptureArgs(0) {}
sub edit : Chained('item') Args(0) {
    my ($self, $c) = @_;
    $self->setup_fields($c, ... );
    $self->make_form;
    # 
}

package Generic;
sub item : Chained('base') PathPart('') CaptureArgs(1) {
    # load thing and store in stash
}
sub setup_fields {}
sub make_form {}
sub handle_form {}

I'd end up with an URL like 
  /thing/123/edit
which IMO looks nicer.


So, is A) just overdoing chained? B) looks ok, but is it using chained 
to it's full potential?

I'd really like to hear some of your thoughts...

-- 
#!/usr/bin/perl                              http://domm.plix.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}



More information about the Catalyst mailing list