[Catalyst] New Bundle::Catalyst

Brandon Black blblack at gmail.com
Tue Nov 15 15:07:09 CET 2005


On 11/15/05, Marcello <m.romani at spinsoft.it> wrote:
> Sebastian Riedel ha scritto:
> >
> > Am 15.11.2005 um 08:54 schrieb Marcello:
> >
> >> I think Singleton would be a nice addition to the list.
> >
> >
> > Doesn't Singleton encourage bad style?
>
> In model classes or DFV profiles it useful to be able to access
> $c->stash or $c->session.
> But maybe that's exactly the bad style you're talking about :-)
>

A couple of times so far I've found myself wanting to use
$c->something from within a model class, but I've avoided it every
time so far by finding a better place to do it.

The most compelling one was to use some data from $c->session in
choosing the timezone of DateTime objects being inflated/deflated from
time columns in the database.  I haven't found a solution I'm really
happy with for this one yet, but currently I just have an unrelated
utility function in lib/MyApp/Utils.pm to display DateTime objects
using a timezone derived from $c->session, and I have to wrap usage of
my timestamp columns in that function ( my $string_for_html_output =
MyApp::Utils::format_for_user($c, $row->time_stamp) ).

Another solution I considered was to set a custom formatter function
on my DateTime objects which watches an environment variable set by
the session code.  Seemed kinda icky to pass data via environment
variables though.

But the mod_perl, and hence my Model objects, will outlive many
sessions from different users, with different settings for what
timezone they want the data displayed in (server time, UTC, some
arbitrary zone of their choosing, or "browser time" detected from
javascript).



More information about the Catalyst mailing list