in reply to Human-readable serialization formats other than YAML?

FWIW: I find the output of Data::Dump far more readable that yaml, and it doesn't make the Pythonesque mistake of relying upon invisible characters for structural integrity.

I did find the standard maximum width of 60 rather limiting, so I patched my version to make it a global so that I can adjust it.

Of course, if you're squeamish about using eval it may not be what you want, but I see no greater risk in the contents of local data files, than local source files. And I see no reason to trade Perl's well-proven, reasonably efficient parser, for less well-proven, invariably highly inefficient, implementations of a design-by-committee spec. in order to avoid using eval.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re: Human-readable serialization formats other than YAML?

Replies are listed 'Best First'.
Re^2: Human-readable serialization formats other than YAML?
by jasonk (Parson) on Apr 23, 2008 at 17:31 UTC

    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!