[Chicago-talk] How do you guys handle controllers?

Jim Thomason thomasoniii at gmail.com
Tue Apr 5 14:45:44 PDT 2005

When people try to graft MVC onto the web in perl, it frequently
breaks down as follows:

1) Model - your database objects. They talk back and forth to your db
through some sort of persistence layer.
2) Template - your display to your user. Usually some sort of
templating system that handles display of the page.
3) Controller - the go-between between the model and template that is
best implemented by mumble mumble to transfer the mumble via mumble
and mumble mumble.

In the abstract, the controller is the middle man. Takes stuff from
the view, hands it off to the model. But I have yet to see an
implementation that really gels for me.

Some things I've seen or tried -

1) monolithic CGIs. You end up with a big switch statement to handle
state as it comes back from the user.
2) State machines. You dump those switch statements into a module,
make each a method, and somehow manage the state to jump between them.
3) Microscopic CGIs, each state becomes its own cgi, which is called
entered as the user progresses through the app.
4) Microscopic state machines - each state in the machine is its own
module, the machine just hops you from state to state.
5) Microscopic controllers. The model objects basically get extended
with controller-type features. "update_users_passed_in" and the like.
6) Observers/notifiers. The template broadcasts a "Hey! Gimme data
request!" A model that understands steps up and says, "Here you go."

And that's what I can think of off the top of my head.

I don't really care for any of 'em, but I'll freely admit that I'm
biased since I'm mainly an object-oriented programmer and this is more
of a procedural issue, and I haven't quite yet been able to graft an
objective-c style controller into the web. Ideally, I'd love to
re-implement Cocoa bindings in perl
(http://www.cocoadevcentral.com/articles/000080.php, if anyone is
curious), but I haven't dreamed up a slick way to do that either.

Anyway, how do you guys do it? What works for you, what have you
tried, what do you hate? I'm looking for maintainability and speed,
mainly. And no, comments like, "try Super::Controller::Widget on CPAN"
do me no good, I want the rationale behind what you do and why it
works (or doesn't work), particular modules can be sorted out later, I
want design suggestions.

Any takers? Controllers really aren't my forte.


More information about the Chicago-talk mailing list