http://www.perlmonks.org?node_id=1033962

salva has asked for the wisdom of the Perl Monks concerning the following question:

Are there any good alternatives to Storable?

I need a serializer that can be instructed to replace some inner objects on the fly just before serializing then using a callback.

Storable has the STORABLE_freeze and STORABLE_thaw hooks but they are not per-object but per-class and besides that, they are methods of the class, not something that can be controlled by the code calling the serializer.

I was thinking of extending Storable, but frankly, its code its one of the worst examples of code rot I have ever seen and so, my question.

update: an example of what I need to do:

my $data = serialize $tree, sub { my $obj = shift; if (check_some_condition($obj)) { return replace($obj) } return (); # serialize $obj as is };