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

Brandon Black blblack at gmail.com
Thu Nov 17 05:54:16 CET 2005


On 11/16/05, Perrin Harkins <perrin at elem.com> wrote:
> Brandon Black wrote:
> > honestly this is all a lot more trouble than just being unclean about
> > it and using a Catalyst::Plugin::Singleton context from my Model
> > during inflate().
>
> Sounds like it, although there is an argument to be made that your model
> should represent the data in a user-independent way.
>

In theory I agree, but in practice, it really doesn't make much
difference for me.  My Model is only used by Catalyst, which in turn
only pulls data to show it to a user.  The (rather massive) backend of
the application on the other side of the database uses straight DBI
anyways.  Or in other words, the database itself represents the data
in a user-independant way, but my Model for Catalyst does not :)

I'd still like to get it right just because I hate being "wrong", I
just don't want to do at much more expense in than the Singleton
method.

[Sorry for the re-arrangement of your paragraphs]
> You already have to do that for things that need HTML-escaping.  This is
> no worse, IMO.

That perhaps brings up a more general case of the same basic issue. 
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?

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.  Or if you don't need your Model outside of Catalyst-land...
it's pretty much where I was at with a single Model using Singleton
contexts.  There's really doesn't seem to be anywhere else to easily
solve the problem but in Model, even though it seems to be
theoretically more of a View issue.

Of course, it's still theoretically wrong I guess.  If I decided to
tack on a Catalyst::View::PDF class to render some pages of my
application for print publishing, HTML-specific & -> &amp; transforms
in Model would be all wrong for PDF use.  But then again, the DateTime
hack would still be fine, as long as the context timezone variable was
set to the timezone you wanted to appear in the published version.

Setting DateTime's timezone isn't really specific to how it is finally
displayed.  In some sense a specific timezone setting is a perspective
or view of a real point in real time, but it's not the kind of view
that has anything to do with HTML vs PDF formatting/escaping, whereas
& -> &amp; obviously is.  & -> &amp; and such should probably be
automatic for all final output interpolated into a template by
View::TT.

Have I waffled enough yet? :)

-- Brandon



More information about the Catalyst mailing list