in reply to Class / package weak association
Looking at the documentation of Data::Dumper, I think you'd be best off by writing appropriate Freezer and Toaster subroutines, but there is $Data::Dumper::Bless which you can set to a subroutine name of your own choosing instead to load the target module:
#!perl use 5.020; use Data::Dumper; $Data::Dumper::Deparse=1; $Data::Dumper::Bless="my_bless"; package Foo {}; say Dumper bless { name => "foo" } => "Foo"; __END__ $VAR1 = my_bless( { 'name' => 'foo' }, 'Foo' );
On the receiving side, you can then implement my_bless as:
sub my_bless( $ref, $class ) { require $class; bless $ref => $class; }
But again, implementing the appropriate Freezer and Toaster is much saner than using Data::Dumper and eval.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Class / package weak association
by tobyink (Canon) on Jun 08, 2021 at 10:11 UTC |