[Catalyst] C::M::{CDBI,DBIC} vs direct Loader use?

Brandon Black blblack at gmail.com
Thu Nov 17 06:22:33 CET 2005


On 11/16/05, Perrin Harkins <perrin at elem.com> wrote:
> Brandon Black wrote:
> > If a Model has data items which are text strings that may contain
> > HTML-illegal characters like '&', and it's not proper to inflate() all
> > your strings with html-escapes like '&amp;' in your data Model - when
> > else could it ever get automagically done without having to wrap every
> > use of a string in your Views with a helper wrapper function to escape
> > them?
>
> It can't ever get automagically done.  Some things are not supposed to
> be HTML-escaped.  You could make it default to escaping everything and
> then turn it off for certain things, but ultimately you still have to
> make this decision for each piece of data if you want to get it right.
>

True that.

> > I'm almost inclined to say that the general solution is to have a
> > Catalyst/Web/HTML/etc-independant data Model that doesn't do such
> > transforms, and subclass it for use as a Catalyst data Model where you
> > insert such transforms and perhaps even depend on current request
> > context.
>
> That's a really bad place to do HTML-escaping.  What if you want to make
> a little command-line tool that uses a model class?  This kind of stuff
> is 100% view.  You can do something hacky if it's sufficient for your
> project, but you are giving up the separation that MVC was supposed to
> give you.
>

Well, if I chose to use the Model from a commandline tool, I'd use the
earlier of the two models in that description, which doesn't have
these transforms in it.

I think Matt's Model->config->{timezone} option in the other thread
may be ideal.  You get to use just one good Model class everywhere,
and no Singleton or direct context access of any kind, yet timezones
get set on inflating correctly based on session context within
Catalyst, and for instance a command-line tool using the same Model
could set Model->config->{timezone} based on $ENV{TZ} or
POSIX::tzset/tzname stuff or what-have-you.

-- Brandon



More information about the Catalyst mailing list