Data::Dump suffers from the same problem as YAML::Syck, that the huge block of text data gets turned into a long, unruly string. And while I do use Data::Dump a lot for debugging, when dealing with deeply-nested objects I find it gets way too wide to read way too quickly, while YAML is usually much easier to follow, due to the amount of whitespace that ends up at the beginning of the line... i.e.
### An object like this...
my $obj = bless( {
this_object_has_some_long_keys => {
and_some_of_them_are_nested => {
fairly_deeply => 'Foo!',
}
},
}, 'Some::Random::ClassName' );
### Will end up like this with Data::Dumper...
bless({
"this_object_has_some_long_keys" => { "and_some_of_them_are_nested"
+=> { fairly_deeply => "Foo!" } },
}, "Some::Random::ClassName")
### YAML output is more readable, IMHO
--- !!perl/hash:Some::Random::ClassName
this_object_has_some_long_keys:
and_some_of_them_are_nested:
fairly_deeply: Foo!
Ultimately, though, your comment did lead me to a solution which works. This is what I'm using now...
From the serializer...
$fh->print(
"package MyApp::TestData::$digest;\n",
"use parent 'Class::Data::Accessor';\n\n\n",
"use YAML qw( Load );\n",
'sub data($$) { __PACKAGE__->mk_classaccessor( @_ ) }'."\n\n",
"data filename => ".dump( $self->filename ).";\n\n",
"data store => Load( <<'$tag' );\n",
YAML::Dump( $store ),
"$tag\n\n",
"data content => <<'$tag';\n",
$self->content,
"$tag\n",
"return __PACKAGE__;\n",
);
Which produces an output file that looks like this:
package MyApp::TestData::PUHmx80zfPHoDloIOrexGA;
use parent 'Class::Data::Accessor';
use YAML qw( Load );
sub data($$) { __PACKAGE__->mk_classaccessor( @_ ) }
data filename => "test-data/some-filename";
data store => Load( <<'___END_OF_TEST_DATA_SECTION___' );
--- &1 !!perl/hash:MyApp::Store
children:
- &2 !!perl/hash:MyApp::Store
___END_OF_TEST_DATA_SECTION___
data content => <<'___END_OF_TEST_DATA_SECTION___';
Original file contents here...
___END_OF_TEST_DATA_SECTION___
return __PACKAGE__;
Then, my regression test scripts can just do this:
for my $file ( <*.pl> ) {
ok( my $class = do $file, "Loaded $file" );
my $p = MyApp::Processor->new(
filename => $class->filename,
content => $class->content,
);
eq_or_diff( $p->store, $class->store );
}