Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by dsheroh (Prior)
on Jul 15, 2019 at 10:48 UTC ( #11102864=note: print w/replies, xml ) Need Help??


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.

  • Comment on Re: YAML::Tiny can't serialize an object reference. Can I unbless a Moo object into a hashref and yammily serialize that?
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11102864]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2020-06-05 04:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (35 votes). Check out past polls.

    Notices?