Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Human-readable serialization formats other than YAML?

by jasonk (Parson)
on Apr 23, 2008 at 17:31 UTC ( [id://682430]=note: print w/replies, xml ) Need Help??


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

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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://682430]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found