Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by jasonk (Parson)
on Apr 23, 2008 at 17:37 UTC ( [id://682433]=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?

Unless there is an option I missed somewhere, XML::Simple can't roundtrip perl objects either...

use Test::More tests => 1; use Test::Differences; use XML::Simple; my $in = bless( { foo => 'bar' }, 'Something' ); my $out = XMLin( XMLout( $in ) ); eq_or_diff( $in, $out ); __END__ 1..1 not ok 1 # Failed test at foo.pl line 8. # +----+------------------+----------------+ # | Elt|Got |Expected | # +----+------------------+----------------+ # * 0|bless( { |{ * # | 1| foo => 'bar' | foo => 'bar' | # * 2|}, 'Something' ) |} * # +----+------------------+----------------+ # Looks like you failed 1 test of 1.

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

Replies are listed 'Best First'.
Re^3: Human-readable serialization formats other than YAML?
by perrin (Chancellor) on Apr 23, 2008 at 17:44 UTC
    Sorry, I missed that you wanted to handle blessed objects. I think you'd better stick with something that understands perl then, like Data::Dumper.
Re^3: Human-readable serialization formats other than YAML?
by tachyon-II (Chaplain) on Apr 24, 2008 at 00:46 UTC
    (Got, Expected) => (Expected, Got)

    Please note that the key return order in a hash is not guaranteed by perl. While it will be constant for a given version of perl on one OS it may well change with a different version of perl or even the same version on a different OS. This has bitten me before when writing tests for CPAN modules. If you are stringifying hashes for comparison purposes make sure you apply a sort to the keys first.

      I was under the impression that the order of unsorted hash keys is not even guaranteed for *each invocation* of perl for any version of perl in any environment ...

      # Perl 5.8.7, perldoc -f keys keys HASH ... The keys are returned in an apparently random order. The actual random order is subject to change in future versions of perl, but it is guaranteed to be the same order as either the "values" or "each" function produces (given that the hash has not been modified). Since Perl 5.8.1 the ordering is different even between different runs of Perl for security reasons (see "Algorithmic Complexity Attacks" in perlsec). ...

      ... ok, at least not since version 5.8.1.

        It bit me back in the 5.6 days in the context of cross platform and different perl versions with stringified hash comparisons in test.t files. The data was the same, but the order was different so the tests failed. At least nowadays it looks like it should bite you immediately instead of after uploading your pride and joy to CPAN only to have it fail tests here, there, and everywhere! Thanks for the info.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://682433]
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: (4)
As of 2024-03-19 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found