[Catalyst-dev] suggestion to augment the default view

John Napiorkowski jjn1056 at yahoo.com
Tue Sep 5 22:49:55 CEST 2006


Hi,

Right now when you forward to a view without any
parameters ($c->view) the default is to either use a
config setting or to just forward to a single view if
there is only one view in the list.  That's how it's
documented although I find the behavior is that if it
finds several views it seems to return the first one
returned based on some internal sorting order.

I propose we augment this behavior to add some rules
to how it matches when there are more than one view
component.  This issue comes to me because I find that
I tend to make a lot of custom views based on the
controller action name.  I do this because I prefer to
move the creation of objects for rendering to the
response body to the View directory so that I can keep
my controllers clean and focused on dispatching tasks.

The Template Toolkit view has a very sane approach to
automatically look for a template based on the action
name.  I'm guessing this is a defacto standard for a
lot of people.  What I am thinking is that the
$c->view should model it's default behavior in a
similar way, that is if you $c->forward($c->view) it
should forward to a view component that is patterned
off the algorithm used by the TT view.

For example:

/C
   feeds->all :Local
   feeds->new :Local
   feeds->popular :Local
/V
   /feeds
      all.pm
      new.pm
      popular.pm

So if you called "/feeds/all" the default view would
be /feeds/all.pm and so forth.

Right now if you don't use a param to $c->view it just
returns the first view it finds (or so I gather from
my tests and looking at the source). I think this
default behavior makes sense when there is only one
view, to make it easier on the people building sites
with TT or other templating languages and that is all
they are using or plan to ever use for a site.  But I
think if we do it the way I've outlined above this
will encourage some additional consistency in the use
of creating views.  A patch for this would be 2 or 3
lines of code I think.  I think we could just update
the sub _comp_singular in Catalyst.pm to return first
a view matching the algorithm or if nothing matches
return the first view it finds, which is the current
behavior.

What do you think?  I'm willing to give this a shot. 
I already have code for this in my Root.pm file,
actually.

--john



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Catalyst-dev mailing list