NAME
Data::Pretty::Filtered - Pretty printing with filtering
DESCRIPTION
The following functions are provided:
FUNCTIONS
add_dump_filter( \&filter )
This registers a filter function to be used by the regular Data::Pretty::dump() function. By default no filters are active.
Since registering filters has a global effect is might be more appropriate to use the dump_filtered() function instead.
remove_dump_filter( \&filter )
Unregister the given callback function as filter callback. This undoes the effect of add_filter.
dump_filtered(..., \&filter )
Works like Data::Pretty::dump(), but the last argument should be a filter callback function. As objects are visited the filter callback is invoked at it might influence how objects are dumped.
Any filters registered with "add_filter()" are ignored when this interface is invoked. Actually, passing undef
as \&filter
is allowed and dump_filtered(..., undef)
is the official way to force unfiltered dumps.
FILTER CALLBACK
A filter callback is a function that will be invoked with 2 arguments: a context object and reference to the object currently visited.
The return value should either be a hash reference or undef
.
sub filter_callback {
my($ctx, $object_ref) = @_;
...
return { ... }
}
If the filter callback returns undef
(or nothing) then normal processing and formatting of the visited object happens.
If the filter callback returns a hash it might replace or annotate the representation of the current object.
FILTER CONTEXT
The context object provides methods that can be used to determine what kind of object is currently visited and where it's located. Please check the module documentation
FILTER RETURN HASH
The following elements has significance in the returned hash:
dump
=>$string
Incorporates the given string as the representation for the current value
object
=>$value
dump
the given value instead of the one visited and passed in as $object.This is basically the same as specifying
dump => Data::Pretty::dump($value)
.comment
=>$comment
Prefixes the value with the given comment string
bless
=>$class
Makes it look as if the current object is of the given
$class
instead of the class it really has (if any). The internals of the object is dumped in the regular way. The$class
can be the empty string to makeData::Pretty
pretend the object was not blessed at all.hide_keys
=> ['key1', 'key2',...]hide_keys
=> \&codeIf the
$object
is a hash dump is as normal but pretend that the listed keys did not exist. If the argument is a function then the function is called to determine if the given key should be hidden.
SEE ALSO
Data::Pretty, Data::Pretty::FilterContext
CREDITS
Credits to Gisle Aas for the original Data::Dump version and to Breno G. de Oliveira for maintaining it.
COPYRIGHT & LICENSE
Copyright(c) 2023 DEGUEST Pte. Ltd.
All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.