in reply to Changing the target of refs of unknown type
Rather than clients keeping a reference to the object, you might use something more akin to the Singleton pattern instead. E.g. something along the lines of Foo->current_instance() that you either use every time you need it or keep in a lexical for (say) the scope of a single sub call.
sub do_bar { my( $a, $b ) = @_; my $cur_foo = Foo->current_instance; ## ## Use $cur_foo . . . ## return $zorch; }
So each time it's used you'll have the "current" Foo. If you need to change the current instance your private code calls something like Foo->_set_instance( $new_foo ) behind the scenes.
|
|---|