in reply to Re: RE: RE: Scoping and Objects
in thread Scoping and Objects
btrott's technique is good -- that's probably the cleanest way to continue what you're doing. Add some methods to access the cache, and any subroutines added through references don't have to know the particulars about how the cache is implemented.
Another option (which I do not recommend if there's any other way around it) is to switch to your object's package and define a new subroutine or install one in the package's symbol table:
orpackage main; # some stuff here package RadCache; sub mangle_cache { # do this and that }
package main; # stuff here my $sub_ref = sub { print "Messing with the cache.\n" }; *RadCache::mangle_cache = $sub_ref; # syntax may be a little off
I think you'd be better off just subclassing your cache object whenever you need to add a callback that works on the internals of the object. That may make your design easier to understand, anyway.
|
|---|