I see. The problem is not with the existence of the Freezer method but the Toaster method, now I understand. This actually looks like a real bug to me. I don't think your code is entirelycorrect though. You call the UNIVERSAL::can() even if the Toaster is not specified. I think the whole change needed is the condition on the line that adds the toaster call:
if ($realpack) { # we have a blessed ref $out .= ', \'' . $realpack . '\'' . ' )'; - $out .= '->' . $s->{toaster} . '()' if $s->{toaster} ne ''; + $out .= '->' . $s->{toaster} . '()' + if $s->{toaster} ne '' and UNIVERSAL::can( $val, $s->{toaster +}); $s->{apad} = $blesspad; }
Update: The problem is that this tests for the Toaster method while the data is serialized/exported, not while it's deserialized/imported. Which might make a difference. With the original code as soon as the export was created with Toaster set to something you can get "notified" about all restored objects, all you have to do is to create a sub in UNIVERSAL package. With your (or mine) change your method only gets called for objects that had the Toaster method at the time of the export.
You could change Data::Dumper to generate something like this:
but I think the easiest solution is to define... map( (UNIVERSAL::can( $_, 'Toaster') ? $_->Toaster() : $_), bless ( {}, 'Package::Name') ), ...
in your script/module and all classes that do not define their own Toaster will inherit this default one.sub UNIVERSAL::Toaster { $_[0] }
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
In reply to Re^3: socio-political guidance sought
by Jenda
in thread socio-political guidance sought
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |