The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Devel::hdb::App::EncodePerlData - Encode Perl values in a -friendly way

SYNOPSIS

  use Devel::hdb::App::EncodePerlData qw(encode_perl_data);

  my $val = encode_perl_data($some_data_structure);
  $io->print( JSON::encode_json( $val ));

DESCRIPTION

This utility module is used to take an artitrarily nested data structure, and return a value that may be safely JSON-encoded.

Functions

encode_perl_data

Accepts a single value and returns a value that may be safely passed to JSON::encode_json(). encode_json() cannot handle Perl-specific data like blessed references or typeglobs. Non-reference scalar values like numbers and strings are returned unchanged. For all references, encode_perl_data() returns a hashref with these keys __reftype String indicating the type of reference, as returned by Scalar::Util::reftype() __refaddr Memory address of the reference, as returned by Scalar::Util::refaddr() __blessed Package this reference is blessed into, as reurned by Scalar::Util::blessed. __value Reference to the unblessed data.

If the reference was not blessed, then the __blessed key will not be present. __value is generally a copy of the underlying data. For example, if the input value is an hashref, then __value will also be a hashref containing the input value's kays and values. For typeblobs and glob refs, __value will be a hashref with the keys SCALAR, ARRAY, HASH, IO and CODE. For coderefs, __value will be the stringified reference, like "CODE=(0x12345678)". For v-strings and v-string refs, __value will by an arrayref containing the integers making up the v-string.

encode_perl_data() handles arbitrarily neste data strucures, meaning that values in the __values slot may also be encoded this way.

SEE ALSO

Devel::hdb

AUTHOR

Anthony Brummett <brummett@cpan.org>

COPYRIGHT

Copyright 2013, Anthony Brummett. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.