Data::D...iltered(3)
πΈ NAME πΈ
Data::Dump::Filtered β pretty printing with filtering π
π DESCRIPTION π
okay so this page gives you the functions below, bestie:
add_dump_filter( \&filter )β registers a filter function to be used by the regularData::Dump::dump()function. By default no filters are active. π
heads up: registering filters has a global effect, so it might be more appropriate to use the dump_filtered() function instead. π
remove_dump_filter( \&filter )β unregisters the given callback function as a filter callback. This undoes the effect ofadd_filter.dump_filtered(..., \&filter )β works likeData::Dump::dump(), but the last argument should be a filter callback function. As objects are visited, the filter callback is invoked and 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 a 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 it returns a hash, it might replace or annotate the representation of the current object. periodt. π
π Filter context π
the context object provides methods that you can use to figure out what kind of object is currently visited and where itβs located. The context object has the following interface:
$ctx->object_refβ alternative way to obtain a reference to the current object.$ctx->classβ if the object is blessed, this returns the class. Returns""for objects not blessed.$ctx->reftypeβ returns what kind of object this is. Itβs a string like"SCALAR","ARRAY","HASH","CODE",...$ctx->is_refβ returns true if a reference was provided.$ctx->is_blessedβ returns true if the object is blessed. Actually, this is just an alias for$ctx->class.$ctx->is_arrayβ returns true if the object is an array.$ctx->is_hashβ returns true if the object is a hash.$ctx->is_scalarβ returns true if the object is a scalar (a string or a number).$ctx->is_codeβ returns true if the object is a function (aka subroutine).$ctx->container_classβ returns the class of the innermost container that contains this object. Returns""if there is no blessed container.$ctx->container_selfβ returns a textual expression relative to the container object that names this object. The variable$selfin this expression is the container itself.$ctx->object_isa( $class )β returnsTRUEif the current object is of the given class or is of a subclass.$ctx->container_isa( $class )β returnsTRUEif the innermost container is of the given class or is of a subclass.$ctx->depthβ returns how many levels deep have we recursed into the structure (from the originaldump_filtered()arguments).$ctx->expr/$ctx->expr( $top_level_name )β returns a textual expression that denotes the current object. In the expression$varis used as the name of the top level object dumped. This can be overridden by providing a different name as argument.
π Filter return hash π
the following elements have significance in the returned hash:
dump => $stringβ incorporate 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. Basically the same as specifyingdump => Data::Dump::dump($value).comment => $commentβ prefix the value with the given comment string.bless => $classβ make it look as if the current object is of the given$classinstead of the class it really has (if any). The internals of the object is dumped in the regular way. The$classcan be the empty string to make Data::Dump pretend the object wasnβt blessed at all.hide_keys => ['key1', 'key2',...]/hide_keys => \&codeβ if the$objectis 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::Dump π
thatβs the whole page, bestie π«Ά this Data::D...iltered(3) footer is giving perl v5.42.0 and 2021-06-29 β iconic, dated, and ready to filter π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Data-Dump 1.25-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms