Skip Menu |

This queue is for tickets about the Data-Dump CPAN distribution.

Report information
The Basics
Id: 85166
Status: resolved
Priority: 0/
Queue: Data-Dump

People
Owner: Nobody in particular
Requestors: MJCARMAN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Expose parent context within filters
When dumping large, multi-layered data structures it would be useful to be able to find out the location within the data structure for the value being dumped. (In particular, I'd like to know the key when dumping hash values.) So far I've been able to work around this using a combination of reftype, depth, state arrays, and knowledge of the structure but that approach is awkward and fragile. The information I want appears to be present in the context object already (the array stored under the 'idx' key) but that isn't exposed via the API.
Seems like a good idea.  Can you take a look at <https://github.com/gisle/data-dump/commit/763a0130e4a8420a959181fdf43d831b48b23657&gt; and tell me if that will provide what you want.  It can be used like this:

use Data::Dump;
use Data::Dump::Filtered;


Data::Dump::Filtered::add_dump_filter(sub {
    my($ctx, $object_ref) = @_;
    if ($ctx->is_ref && $ctx->depth > 1) {
        return {
            comment => $ctx->expr,
        }
    }
    return;
});


my %foo = (
    bar => {
        a => [1, 2, 3],
        b => {
            zot => 1,
        },
    }
);

dd(\%foo);
On Fri May 10 06:30:46 2013, GAAS wrote: Show quoted text
> Seems like a good idea. Can you take a look at > <https://github.com/gisle/data-dump/commit/763a0130e4a8420a959181fdf43d831b48b23657> > and tell me if that will provide what you want.
That works perfectly for my use case. Thank you.