Dear Perl lazyweb: how to construct read-only data objects out of JSON?

I recently updated a client called WebService::Geocodio for the geocoding service. Traditionally, geocoding means turning a mailing address into latitude/longitude coordinates (or the reverse operation, turning latitude/longitude into a mailing address.)

In a recent update of the upstream service they included the ability to fetch additional data fields including timezone, congressional district, school district and so forth. Is there a good CPAN module (or a recommendation) to take a Perl data structure like a hash and turn it into a Moo(::Lax) object "automagically?" I had a look but I didn't find anything especially suitable.

These data structures are purely informational in nature and just have getters for their attribute names. This would be less difficult to accomplish using Moose (obviously) but I'm wondering if there are any suggestions for something that installs getters for hash keys dynamically and is Moo-friendly.



Here's a quick solution using Class::Tiny. It's not much more difficult with Moo.

how about

Leave a comment

About Mark Allen

user-pic Singer, dad, nerd, not necessarily in that order. @bytemeorg