in reply to Re: Class / package weak association
in thread Class / package weak association
To expand a bit, the configuration setting is $Data::Dumper::Deparse to make Data::Dumper also dump the (deparsed) source code of code references. But as LanX already said, the source representation is functionally mostly identical but will not necessarily represent the original code identically.
The interesting part is once you have subroutines closing over common variables, like for example getters/setters:
my $name = 'foo'; my $package = { getter => sub ( $self ) { return $self->{$name} }, setter => sub ( $self, $value ) { return $self->{$name} = $value } +, }
You need to dump these at once so that Data::Dumper dumps the reference to the common variable $name as a single variable. This happens whenever your class has autogenerated methods (like with Moo, Moose etc.).
Depending on how much control you have over the source code of the class to be dumped, this can make things far more hairy than you want.
|
|---|