NAME
JavaScript::HashRef::Decode - a JavaScript "data hashref" decoder for Perl
DESCRIPTION
This module "decodes" a simple data-only JavaScript "variable value" and returns a Perl data structure constructed from the data contained in it.
It only supports "data" which comprises of: hashrefs, arrayrefs, single- and double-quoted strings, numbers, and "special" token the likes of "undefined", "true", "false", "null".
It does not support functions, nor is it meant to be an all-encompassing parser for a JavaScript object.
If you feel like the JavaScript structure you'd like to parse cannot effectively be parsed by this module, feel free to look into the Parse::RecDescent grammar of this module.
Patches are always welcome.
SYNOPSIS
use JavaScript::HashRef::Decode qw<decode_js>;
use Data::Dumper::Concise;
my $js = q!{ foo: "bar", baz: { quux: 123 } }!;
my $href = decode_js($js);
print Dumper $href;
{
baz => {
quux => 123
},
foo => "bar"
}
EXPORTED SUBROUTINES
decode_js($str)
Given a JavaScript "variable value" thing (i.e. an hashref or arrayref or string, number, etc), returns a Perl hashref structure which corresponds to the given data
decode_js('{foo:"bar"}');
Returns a Perl hashref:
{ foo => 'bar' }
The Parse::RecDescent internal interface is reused across invocations.
SEE ALSO
The ECMAScript Object specification: http://www.ecmascript.org/
AUTHOR
Marco Fontani - MFONTANI@cpan.org
CONTRIBUTORS
Aaron Crane
COPYRIGHT
Copyright (c) 2013 Situation Publishing LTD