Author image Steven Haryanto
and 1 contributors


Data::Dump::Partial - Dump data structure compactly and potentially partially


version 0.05


 use Data::Dump::Partial qw(dump_partial dumpp);

 dump_partial([1, "some long string", 3, 4, 5, 6, 7]);
 # prints something like: [1, "some long st...", 3, 4, 5, ...]

 # specify options
 dumpp($data, $more_data, {max_total_len => 50, max_keys => 4});

 # mask passwords specified in hash key values
 dumpp({auth_info=>{user=>"steven", password=>"secret"}, foo=>1, bar=>2},
 # prints something like:
 # {auth_info=>{user=>"steven", password=>"***"}, foo=>1, bar=>2}



dump_partial(..., $opts)

Dump one more data structures compactly and potentially partially. Uses Data::Dump::Filtered as the backend.

By compactly, it means all indents and comments and newlines are removed, so the output all fits in one line.

By partially, it means only up to a certain amount of data are dumped/shown: string longer than a certain length will be truncated (with "..." appended in the end), array more than a certain number of elements will be truncated, and hash containing more than a certain number of pairs will be truncated. The total length of dump is also limited. When truncating hash you can specify which keys to discard/preserve first. You can also mask certain hash key values (for example, to avoid exposing passwords in dumps).

$opts is a hashref, optional only when there is one data to dump, with the following known keys:

  • max_total_len => NUM

    Total length of output before it gets truncated with an ellipsis. Default is 80.

  • max_len => NUM

    Maximum length of a scalar (string, etc) to show before the rest get truncated with an ellipsis. Default is 32.

  • max_keys => NUM

    Number of key pairs of a hash to show before the rest get truncated with an ellipsis. Default is 5.

  • max_elems => NUM

    Number of elements of an array to show before the rest get truncated with an ellipsis. Default is 5.

  • precious_keys => [KEY, ...]

    Never truncate these keys (even if it results in max_keys limit being exceeded).

  • worthless_keys => [KEY, ...]

    When needing to truncate hash keys, search for these first.

  • hide_keys => [KEY, ...]

    Always truncate these hash keys, no matter what. This is actually also implemented by Data::Dump::Filtered.

  • mask_keys_regex => REGEX

    When encountering keys that match certain regex, mask the values with '***'. This can be useful if you want to mask passwords, e.g.: mask_keys_regex => qr/\Apass\z|passw(or)?d/i. If you want more general masking, you can use pair_filter.

  • pair_filter => CODE

    CODE will be called for each hash key/value pair encountered in the data. It will be given ($key, $value) as argument and is expected to return a list of zero or more of keys and values. The example below implements something similar to what mask_keys_regex accomplishes:

     # mask each password character with '*'
     hash_pair_filter => sub {
         my ($k, $v) = @_;
         if ($k =~ /\Apass\z|passw(or)?d/i) {
             $v =~ s/./*/g;
         ($k, $v);
  • dd_filter => \&sub

    If you have other Data::Dump::Filtered filter you want to execute, you can pass it here.


An alias for dump_filtered().


What is the point/purpose of this module?

Sometimes you want to dump a data structure, but need it to be short, more than need it to be complete, for example when logging to log files or database.

Is the dump result eval()-able? Will the dump result eval() to produce the original data?

Sometimes it is/will, sometimes it does/will not if it gets truncated.




Please visit the project's homepage at


Source repository is at


Please report any bugs or feature requests on the bugtracker website

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.


Steven Haryanto <>


This software is copyright (c) 2014 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.