NAME

VERSION

This document describes version 0.28 of Data::Clean::Base (from Perl distribution Data-Clean-JSON), released on 2015-06-10.

METHODS

new(%opts) => $obj

Create a new instance.

Options specify what to do with problematic data. Option keys are either reference types or class names, or -obj (to refer to objects, a.k.a. blessed references), -circular (to refer to circular references), -ref (to refer to references, used to process references not handled by other options). Option values are arrayrefs, the first element of the array is command name, to specify what to do with the reference/class. The rest are command arguments.

Note that arrayrefs and hashrefs are always walked into, so it's not trapped by -ref.

Default for %opts: -ref => 'stringify'.

Available commands:

['stringify']

This will stringify a reference like {} to something like HASH(0x135f998).

['replace_with_ref']

This will replace a reference like {} with HASH.

['replace_with_str', STR]

This will replace a reference like {} with STR.

['call_method']

This will call a method and use its return as the replacement. For example: DateTime->from_epoch(epoch=>1000) when processed with [call_method => 'epoch'] will become 1000.

['call_func', STR]

This will call a function named STR with value as argument and use its return as the replacement.

The command argument specifies the number of references to clone as a limit (the default is 50), since a cyclical structure can lead to infinite cloning. Above this limit, the circular references will be replaced with a string "CIRCULAR". For example:

my $a = [1]; push @$a, $a;

With -circular => ['clone', 2] the data will be cleaned as:

[1, [1, [1, "CIRCULAR"]]]

With -circular => ['clone', 3] the data will be cleaned as:

[1, [1, [1, [1, "CIRCULAR"]]]]

$obj->clean_in_place($data) => $cleaned

Clean $data. Modify data in-place.

$obj->clone_and_clean($data) => $cleaned

Clean $data. Clone $data first.

ENVIRONMENT

LOG_CLEANSER_CODE => BOOL (default: 0)

Can be enabled if you want to see the generated cleanser code. It is logged at level trace.