[Dbix-class] DateTime personalization
Matt S Trout
dbix-class at trout.me.uk
Thu Nov 13 21:43:34 GMT 2008
On Fri, Oct 31, 2008 at 11:35:32PM +0100, Bernhard Graf wrote:
> For my datetime and date fields I use DBIC:InflateColumn::DateTime and
> DBIC:Timestamp.
>
> Now I wanted to personalize those DateTime objects for the authenticated
> user: Time zone and output format should be set on inflation, according
> to what the authenticated user has configured in his/her personal
> settings.
>
> The inflate-part for inflate_column now looks like this:
>
> inflate => sub {
> my ($value, $obj) = @_;
> my $z;
> my $dt = $obj->_datetime_parser->$parse($value);
> $dt->set_time_zone($timezone) if $timezone;
> $z = $obj->get_user_time_zone
> and $dt->set_time_zone($z);
> $z = "get_user_${type}_format";
> $z = $obj->$z()
> and $dt->set_formatter($z);
> return $dt;
> },
>
> And also in this package there are three stub methods:
>
> sub get_user_time_zone { }
> sub get_user_datetime_format { }
> sub get_user_date_format { }
I wonder if we'd be better off simply moving the inflation process to being
a method - so we do
inflate => sub {
my ($value, $obj) = @_;
return $obj->_inflate_datetime($type, $value, $colname);
}
or so - that way it can trivially be subclassed, rather than us continuing to
shoehorn random features into the module that (while useful to many users) are
just a performance hit for the many more that don't use them.
Thoughts? Patches? :)
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
More information about the DBIx-Class
mailing list