[Catalyst] Patch for Catalyst::View::Mason

Jonathan Rockway jon at jrock.us
Fri Mar 7 22:44:54 GMT 2008


* On Fri, Mar 07 2008, Christopher H. Laco wrote:
> David Jack Wange Olrik wrote:
>>
>> On 07/03/2008, at 22.22, Florian Ragwitz wrote:
>>
>>> I want to keep the default behaviour to not break existing code and
>>> to be consistent with most other catalyst views.
>>>
>>> However I'll think about implementing a new configuration option
>>> that, when enabled, will always append template_extension.
>>
>>
>> Great, then I hope the other View authors will consider being
>> consistent with you ;)
>>
>
> Ideally, this should be, and was started to be extraced out into a
> based class...
>
> http://search.cpan.org/~jrockway/Catalyst-View-Templated-0.02/lib/Catalyst/View/Templated.pm

This was a failure, and we I don't think we can fix the various Views on
CPAN until 5.8.

What we really needed to have done was to implement views as a
composition of a bunch of roles.

Templated tried to factor out a minimum set of functionality from the
template engine-based views.  But it wasn't minimal enough.  Every
templating system has its own odd quirks; TT has a ton of extra config,
mason does weird things with variables, Template::Declare uses modules
instead of filenames, clearsilver can't call back into the application,
etc.

So what we need to do is say, by default Views are "new" and "render" (*).
Then we can apply a role to create "process" from "render".  Then we can
add a "Templated" role which adds InstancePerContext and
$view->set_template.

Then you can write your own roles to do things like guess the action
name and extension and set that to the template name.  Or whatever, it's
a simple matter of:

  package GuessExtension;
  use Moose::Role;

  around set_template => sub {
      my ($super, $self, $template) = @_;
      do your munging;
      return $super->($self, $munged_template);
  }

Because roles are sane, you can introspect the final composition and
pragmatically learn about how a certain view works.  This is important
for things like View::Email, which currently just makes random
assumptions about the templating backend.  Random assumptions are
fragile.

Anyway, it's possible to prototype this now... but it's not really
possible to replace all the Views on CPAN with this.  (For one thing,
NEXT and Moose play together terribly.)  Anyone interested in this
should go ahead and implement it, though.

(*) This is wonderfully non-specific-to-Catalyst, btw.  See my
"Providers" in App::TemplateServer.  Apply a role that adds a process
method and you can use 'em in Catalyst.  That's reuse.

Regards,
Jonathan Rockway



More information about the Catalyst mailing list