[Catalyst-dev] What View::Templated does for you :)

Jonathan Rockway jon at jrock.us
Thu Sep 20 19:45:47 GMT 2007


Now's a good time to discuss the internals of View::Templated  so that
we can get this thing stable (or deleted) sometime soon :)

Here's what sort of fun stuff the View does for the author.

* $view->template is a rw accessor that will always return a template to
render.  It looks to see if the user has set a template via
$c->view->template('name'), and if he has, returns that.  Next, it looks
for $c->stash->{template} so that it is back-compatible with that
convention.  Finally, it returns $c->action concatenated with the
TEMPLATE_EXTENSION.  (That's the reason why I initially unified the
configs).

* process works correctly.  It determines the charset of the data and
sets the content-type header appropriately (latin-1 data is *NOT* utf-8;
that has caused View::TT users loads-of-pain judging from IRC
conversations and the user list).  The content-type defaults to
text/html, but can be changed at new time with the CONTENT_TYPE config
option.

* render works correctly, and better than the version that most people
have cargo-culted.  It uses ACCPET_CONTEXT, so you can just say
$view->render('template', { args => ... }).  Template and args are both
optional (see the docs for details).

* preprocessing of $c->stash before sending it to the _render method.
$c, $c->req->base, and $c->config->name get turned into "c", "base", and
"name" in the stash passed to the real rendering function (_render),
which then treats them however it treats other keys in the stash.  This
is a TT convention, but I wanted it to be the same for any view.
Unfortunately, it doesn't really work for things like Template::Declare
that only know/care about $c. (Mason provides $c, $name, $base... but it
doesn't change $c->stash->{foo} to $foo.  So there the system breaks
down :)  Thoughts?

Anyway, just wanted to clear this up so I can get some more feedback.
The idea of ::Templated is to make writing an interface to a templating
engine simple for the author and simple to use for the users.  As an
author, you don't need to know any details of Catalyst to get your View
to work; ::Templated handles that for you.  (I like this approach... do
you?)

The version on CPAN was my first stab, but it is of course open to
changes.  Thanks to everyone that has tried it out so far!

Regards,
Jonathan Rockway




More information about the Catalyst-dev mailing list