Acme-Dump-And-Dumper
view release on metacpan or search on metacpan
Acme::Dump::And::Dumper - dump data structures without seeing any object guts
# 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' => [
Whenever possible, the module will try to deep clone the structure
before messing with it and dumping it. **However**, since not everything
is deep clonable, if the deep clone fails, the module will modify the
original data structure, and method call on what **used to be** objects
will obviously fail.
# HISTORY
This module arose from my frustration of trying to get rid of object
guts in my dumped data (e.g. dumping `Foo::Bar` that is a blessed
hashref, would also dump all the contents of that hashref).
Subsequently, during a conversation on IRC, `tm604` came up with
a hack using `$Data::Dumper::Freezer`, and the following comment
from `hoelzro` made me decide to release a module I could actually
use, when I don't want to see any object guts.
<hoelzro> Data::Dumper::And::Dumper
* hoelzro ducks
<hoelzro> s/Dumper/Dump/ # ruined my own awful joke
examples/dump.pl view on Meta::CPAN
# VERSION
use lib qw{../lib lib};
use Acme::Dump::And::Dumper;
my $data = {
foo => "bar\nber",
ber => {
beer => [qw/x y z/],
obj => bless([], 'Foo::Bar'),
},
};
print DnD $data;
lib/Acme/Dump/And/Dumper.pm view on Meta::CPAN
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;
}
lib/Acme/Dump/And/Dumper.pm view on Meta::CPAN
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' => [
lib/Acme/Dump/And/Dumper.pm view on Meta::CPAN
Whenever possible, the module will try to deep clone the structure
before messing with it and dumping it. B<However>, since not everything
is deep clonable, if the deep clone fails, the module will modify the
original data structure, and method call on what B<used to be> objects
will obviously fail.
=head1 HISTORY
This module arose from my frustration of trying to get rid of object
guts in my dumped data (e.g. dumping C<Foo::Bar> that is a blessed
hashref, would also dump all the contents of that hashref).
Subsequently, during a conversation on IRC, C<tm604> came up with
a hack using C<$Data::Dumper::Freezer>, and the following comment
from C<hoelzro> made me decide to release a module I could actually
use, when I don't want to see any object guts.
<hoelzro> Data::Dumper::And::Dumper
* hoelzro ducks
<hoelzro> s/Dumper/Dump/ # ruined my own awful joke
t/01-dump.t view on Meta::CPAN
#!perl -T
use strict;
use warnings FATAL => 'all';
use Test::More;
plan tests => 1;
use Acme::Dump::And::Dumper;
my $obj = bless([qw/x y z/], 'Foo::Bar');
my $data_orig = {
ber => {
obj => [ $obj, $obj ],
},
};
my $output_DnD = <<'END';
$VAR1 = {
'ber' => {
( run in 0.866 second using v1.01-cache-2.11-cpan-de7293f3b23 )