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 ); }

www.jasonkohles.com
We're not surrounded, we're in a target-rich environment!

In reply to Re^2: Human-readable serialization formats other than YAML? by jasonk
in thread Human-readable serialization formats other than YAML? by jasonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.