JSON Archives

Thoughts on Marshalling and Unmarshalling in Zydeco

Prompted by a recent question on PerlMonks, I've been thinking a bit recently on marshalling and unmarshalling Perl objects. If you're happy using Data::Dumper's format, then it's trivial, but today we're looking at JSON.

If you just want to encode your objects as JSON, that's very easy. Just add a TO_JSON method to all your classes. This can be done in a role to eliminate duplication, and in most cases can be as simple as:

The difficulty comes in going the other direction.

Be Your Own Big Brother

Many modern browsers (including recent versions of Firefox and Opera) support the W3C's geolocation API. This is a standardised mechanism for Javascript to ask your browser where it geographically is in the world. Typically the browser will then pop up a message asking you if you wish to reveal this information, giving you the opportunity to opt out.

But how does your browser know where it is? The method that Firefox and Opera both seem to use is this:

  1. They sniff data o…

About Toby Inkster

user-pic I'm tobyink on CPAN, IRC and PerlMonks.