-------- Original Message  --------
Subject: Re: DefaultFormatter for DateTime
From: Zefram <zef...@fysh.org>
To: p p <qua...@gmail.com>
Cc: datetime@perl.org
Date: Thu Nov 25 2010 13:36:57 GMT+0100 (CET)

p p wrote:
With DefaultFormatter I can simply do:

Eww, global variable.  You can do that in your modules, and so can anyone

There is DefaultLocale in DateTime so I've thought that
that door is already opened.

If You do not like global variables make it class function as DefaultLocale already is.

package DateTime;
...
{
 my DefaultFormatter=undef;
 sub DefaultFormatter {
        if(@_){
                $DefaultFormatter=shift;
        }
        return DefaultFormatter;
 }
}
...


or


package DateTime;
...
 use base qw(Class::Data::Inheritable);
 DateTime>mk_classdata('DefaultFormatter');
...

else in theirs, but if you both do it and your modules end up in the
same process then you'll step on each other's toes.

You really want to find a more convenient way for you to explicitly
attach a particular formatter to each column that you declare.  Such as
write a wrapper for the DBIC stuff.

I use catalyst/dbic tools to generate dbic classes and cannot find easy
way to pass my own DateTime class nor formatter (cannot pass foramtter object when generating classes sources, and passing formatter class name
would cost me because of creating formatter object when printing every
column value ) as argument for genereator. It has hardcoded DateTime class name.

Usually there is one way presenting date in application. May differ on appllication instance, user preferences, but once selected
it is used consistently in application/web page request.

So DefaultFormatter makes life easier just as _stringify or DefaultLocale does.

--
piotr

Reply via email to