Re: Storable and DateTime::Format::Strptime

2016-10-22 Thread Dave Rolsky

On Sat, 22 Oct 2016, Bill Moseley wrote:


Should or can the formatter have a Storable hook to remove the parser?   Any 
suggestions on an easy workaround?


It'd probably be relatively easy to add Storable hooks to the module. All 
it needs to do is save the arguments passed to new() and then freeze 
those instead of the object itself.


Patches would be welcome.


Cheers,

-dave

/*
http://VegGuide.org   http://blog.urth.org
Your guide to all that's veg  House Absolute(ly Pointless)
*/

Storable and DateTime::Format::Strptime

2016-10-22 Thread Bill Moseley
Howdy!

I upgraded Storable on an old app and started to get this error from
Storable:

Can't store REGEXP items at ...


Turns out the ORM we have is setting a DateTime::Format::Strptime formatter
on the DateTime objects and the formatter has a regex for the parser.

This happens as they are "inflated" from the DB,  Some of these are later
cached which triggers the error.

Should or can the formatter have a Storable hook to remove the parser?
Any suggestions on an easy workaround?

Granted, it's questionable putting the formatter on the DateTime objects
when pulled from the database instead of in, say, a view.   But removing it
now would mean hunting down all the places where the DateTime objects are
rendered for display.


use strict;
use warnings;
use DateTime;
use Storable 'nfreeze';
use DateTime::Format::Strptime;

my $dt = DateTime->now;

my $format = DateTime::Format::Strptime->new(
pattern => '%x %X',
locale  => 'en_us' );

$dt->set_formatter( $format );
nfreeze( $dt );



-- 
Bill Moseley
mose...@hank.org