in reply to Re^2: searching for an object reference
in thread searching for an object reference
The issue with the above is keeping track of $new_obj. This needs to be a package variable, and the class itself has to be a singleton - unless a hash with package names as keys. Any ideas ? For now, deepcopying looks the simplest solution to me, as the data to be traversed is small in size. But I think your idea can be generalized to a Redirector CPAN module !package Redirector; my $new_obj; # Redirect all methods calls of object A to object B. sub redirect { my $new_obj = shift; my @methods = @_ || 'all'; <instrument the methods so that Redirector::foo is called instead of old_obj::foo> } sub print { my $real_obj = shift; # Conveniently switch the object. $new_obj->print(@_); }
|
|---|