Subject: | Dump() affects success of subsequent each() |
Thank you for the module. I use it often.
It seems that YAML::Syck::Dump($hashref) doesn't reset the iterator for
%$hashref when it's done. A subsequent each(%$hashref) fails to iterate
at all. Placing keys(%$hashref) before the each() call resets the
hash's iterator and allows each() to iterate normally.
I've attached a Test::More test case illustrating the problem.
I've flagged the Severity as "Important". No offense will be taken if
you flag it as less severe.
Subject: | yaml-syck-each.pl |
#!/usr/bin/env perl
use warnings;
use strict;
use Test::More tests => 2;
use YAML::Syck;
my $some_hashref = { a => 1, b => 2 };
my $expected_iterations = scalar keys %$some_hashref;
is(
count_each_iterations($some_hashref),
$expected_iterations,
"each() iterates properly before YAML::Syck::Dump",
);
# Perform the Dump.
my $some_yaml_dump = YAML::Syck::Dump($some_hashref);
is(
count_each_iterations($some_hashref),
$expected_iterations,
"each() iterates properly after YAML::Syck::Dump",
);
exit;
sub count_each_iterations {
my $hashref = shift;
my $iterations = 0;
while (my ($k, $v) = each %$hashref) {
$iterations++;
}
return $iterations;
}