[Catalyst] Re: CGI.pm and Catalyst?

Aristotle Pagaltzis pagaltzis at gmx.de
Fri Mar 7 10:39:33 GMT 2008


* Martin Ellison <m.e at acm.org> [2008-03-07 09:30]:
> Is there anything attached to Catalyst similar to the CGI.pm
> module? That is, creating the HTML by a series of procedure
> calls rather than by instantiating a template?

You are looking for Template::Declare.

> Or is there some way to link up the existing CGI module?
> $c->response->body(ul(li(q{hello}),
> li(q{world})))) ?

No.

> Or is it not a good idea?

Yes and no.

It’s a really really REALLY bad idea to mix your display logic
into your controllers, much less your model.

Most people therefore say that you should use a template system
with a minilanguage. But the reason that doing this is good is
that it forces you to write your display logic in a separate file
without easy access to the rest of the code.

In other words, it forces you to properly separate concerns: the
controllers only translate HTTP into model and view calls, and
only the model has business logic, and the view does nothing else
than translate the stash into output.

But the language in which your display logic is written doesn’t
much matter. (In fact, the minilanguages are usually terrible,
like writing shell and awk scripts when you could be writing
Perl.) It’s not an issue to write Perl to generate your output,
as long as you keep that Perl code in separate modules whose
*only* job is to render the stash.

And that’s what Template::Declare makes you do.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



More information about the Catalyst mailing list