Data-Pack

 view release on metacpan or  search on metacpan

t/01_misc.t  view on Meta::CPAN

#!/usr/bin/env perl
use warnings;
use strict;
use Data::Pack ':all';
use Test::More tests => 3;
use Test::Differences;
my $h = {
    a => 1,
    b => [ 2 .. 4, undef, 6 .. 8 ],
    c => [],
    d => {},
    e => undef,
    f => (
        bless {
            f1 => undef,
            f2 => 'f2',
        },
        'Foo'
    ),
    g => {
        g1 => undef,
        g2 => undef,
        g3 => [ undef, undef, undef ],
        g4 => {
            g4a => undef,
            g4b => undef,
        },
    },
    h => [ { a => 23 }, { a => 42 } ],
};
my $hp = {
    a => 1,
    b => [ 2 .. 4, 6 .. 8 ],
    f => (bless { f2 => 'f2', }, 'Foo'),
    h => [ { a => 23 }, { a => 42 } ],
};
eq_or_diff(scalar(pack_data($h)), $hp, 'pack_data(hashref), scalar context');
my %h2 = pack_hash(%$h);
eq_or_diff(\%h2, $hp, 'pack_hash(hash), list context');

eq_or_diff(scalar(pack_data({ a => undef })), {}, 'pack_data(hashref)');



( run in 1.275 second using v1.01-cache-2.11-cpan-df04353d9ac )