http://qs321.pair.com?node_id=542443


in reply to Re^3: Safely altering the behaviour of heavily used modules
in thread Safely altering the behaviour of heavily used modules

It can't ever work, because of the problem of references.

Storable supports circular references correctly, and the implementation of this means that what is in $_[0] may already have 4 or 5 other Perl references pointing to it by the time the hook gets called.

So if you were to replace $_[0] with $singleton, you would break all the other references.

If Perl references were purely heirachal, this wouldn't be a problem.

And that is why we have a seperate method. Because it provides an alternative that certifies that that class won't end up creating circular references below it, and thus that a modify/return type result will work sanely.

Read through bug #4901 and you might be able to understand it a bit more. It took me a long time.