Acme-Dump-And-Dumper

 view release on metacpan or  search on metacpan

lib/Acme/Dump/And/Dumper.pm  view on Meta::CPAN

package Acme::Dump::And::Dumper;

use strict;
use warnings;

our $VERSION = '1.001005'; # VERSION

require Exporter;
our @ISA = qw/Exporter  Data::Dumper/;
our @EXPORT_OK = @Data::Dumper::EXPORT_OK;
our @EXPORT    = ( 'DnD', @Data::Dumper::EXPORT );

use Data::Rmap;
use Scalar::Util qw/blessed  refaddr/;
use Data::Dumper ( @Data::Dumper::EXPORT, @Data::Dumper::EXPORT_OK, );
use Storable qw/dclone/;
$Storable::Deparse = 1;

sub DnD {
    my @in = @_;

    my @out;
    for my $data ( @in ) {
        my $working_data = eval { dclone $data };
        $working_data = $data
            unless defined $working_data;

        rmap_all {
            my $state = shift;
            if ( defined blessed $_) {
                delete $state->seen->{ refaddr $_ };
                $_ = 'obj[' . ref($_) . ']';
            }
        } $working_data;

        push @out, Dumper $working_data;
    }

    return wantarray ? @out : join '', @out;
}

1;

__END__

=encoding utf8

=for stopwords Dump'n'Dumper clonable pneumonic

=head1 NAME

Acme::Dump::And::Dumper - dump data structures without seeing any object guts

=head1 SYNOPSIS

    use Acme::Dump::And::Dumper;

    my $data = {
        foo => 'bar',
        ber => {
            beer => [qw/x y z/],
            obj  => bless([], 'Foo::Bar'),
        },
    };

    print DnD $data;

    ## Prints:
    ## $VAR1 = {
    ##      'ber' => {
    ##                 'obj' => 'obj[Foo::Bar]',
    ##                 'beer' => [
    ##                             'x',
    ##                             'y',
    ##                             'z'
    ##                           ]
    ##               },
    ##      'foo' => 'bar'
    ## };

    # All the Data::Dumper stuff is still there...
    $Data::Dumper::Useqq = 1;
    print DnD "Foo\nBar";

    # ... even the original Dumper()
    print Dumper "Foo\nBar";

=head1 DESCRIPTION

A L<Data::Dumper>, with an additional sub that's like C<Dumper()>
but doesn't dump the contents of object refs.

=head1 EXPORTS

In addition to all the stuff available for export in L<Data::Dumper>,
this module provides C<DnD()> function (pneumonic: "Dump'n'Dumper").

=head2 C<DnD>

    print DnD $data;

    # Data::Dumper's vars are still available:
    $Data::Dumper::Useqq = 1;
    print DnD "Foo\nBar";

Takes the same stuff and returns the same output as



( run in 1.476 second using v1.01-cache-2.11-cpan-5b529ec07f3 )