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


in reply to YAML::Tiny can't serialize an object reference. Can I unbless a Moo object into a hashref and yammily serialize that?

Data::Structure::Util includes an unbless function which can do that.

However, my personal preference for situations like this is to give my objects an ->unblessed method which copies the object's contents into a new, unblessed hashref and returns that, leaving the original object intact. It takes up a little more time and memory than unblessing the original reference, of course, but it allows me to continue using the object as an object afterwards, If you're just going to free the object after unblessing and dumping it, then that's not a concern, so Data::Structure::Util::unbless would probably make more sense in that situation.