in reply to Creating a Moose object and serializing it

I usually use `Storable`, but it seems not to like coderefs.

I was doing some tests with Storable and coderefs a couple of weeks ago. The details are under the CODE REFERENCES section (not surprisingly :-) and begin "Since Storable version 2.05, ..." so you might want to check the version you're running.

My use statement looks like this:

use Storable qw{nstore retrieve}; { no warnings qw{once}; $Storable::Deparse = 1; $Storable::Eval = 1; }

I wasn't using Moose but I was storing blessed objects containing coderefs.

Anyway, if you do decide to take the Storable route, that may help.

-- Ken

Replies are listed 'Best First'.
Re^2: Creating a Moose object and serializing it
by daverave (Scribe) on Oct 23, 2010 at 14:33 UTC
    Thanks Ken, that was helpful!

    Could you please explain the purpose of blocking the statements following `use`?

      Near the beginning of the script I have all warnings switched on:

      use warnings;

      The warnings pragma is lexically scoped and so affects the entire script.

      When I first started to test Storable with coderefs, my code looked like this:

      use Storable qw{nstore retrieve}; $Storable::Deparse = 1; $Storable::Eval = 1;

      Perl emitted a warning that each of those variables had only been used once and this possibly indicated an error in my code. I knew there wasn't an error and I didn't want this warning to be constantly displayed. I could have switched the warning off like this

      use Storable qw{nstore retrieve}; no warnings q{once}; $Storable::Deparse = 1; $Storable::Eval = 1;

      but that would have turned off the warning for the entire script: maybe later in the script there was a real error which now wouldn't be reported.

      By using a block I constrain the scope of the warning suppression to just that block. Furthermore, it also highlights what has been done. The following is equivalent but uses more code and is less obvious:

      use Storable qw{nstore retrieve}; no warnings q{once}; $Storable::Deparse = 1; $Storable::Eval = 1; use warnings q{once};

      Compare that with the block form:

      use Storable qw{nstore retrieve}; { no warnings qw{once}; $Storable::Deparse = 1; $Storable::Eval = 1; }

      -- Ken

        Thank you!