Subject: | Moose::Object::dump() |
Date: | Fri, 22 Feb 2008 11:06:46 +0100 |
To: | bug-moose [...] rt.cpan.org |
From: | David Raab <d.raab [...] angel.de> |
(Sorry for my bad english first, i hope you will understand me)
Hi,
there is a little bug in Moose::Object when you use the dump() Method.
In Moose::Object::dump you set $Data::Dumper::Maxdepth global. If you
later call Data::Dumper::Dumper then the Maxdepth Option is used.
An example:
#!/usr/bin/perl
# Core Module
use strict;
use warnings;
{
package Point;
use Moose;
has 'x' => (is => 'rw', isa => 'Int');
has 'y' => (is => 'rw', isa => 'Int');
}
my $anno = {
is => [ 0 .. 9 ],
bla => [ 10 .. 20 ],
};
my $point = Point->new;
$point->x(640);
$point->y(480);
print $point->dump(1);
print Data::Dumper::Dumper($anno);
This prints out:
$VAR1 = bless( {
'y' => 480,
'x' => 640
}, 'Point' );
$VAR1 = {
'bla' => 'ARRAY(0x83cd25c)',
'is' => 'ARRAY(0x8383d30)'
};
But the second dump is not correct. It should print the complete
Structure. But because you not localize $Data:Dumper::Maxdepth there
will only print a depth of one.
You cam simple fix this, just localize $Data::Dumper::Maxdepth (you
always should localize Package variables).
74c74
< $Data::Dumper::Maxdepth = shift if @_;
---
Show quoted text
> local $Data::Dumper::Maxdepth = shift if @_;
After that the above example will correctly print:
$VAR1 = bless( {
'y' => 480,
'x' => 640
}, 'Point' );
$VAR1 = {
'bla' => [
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20
],
'is' => [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
]
};