and expect $x to be dynamic. This I understand. What I don't understand is how to accomplish something.sub outer { my $x; $x=shift; sub inner { print "x is $x\n"; } }
The concept is that regardless of how many instances of Node:: that you create, the same Cache:: object will be used to improve performance.package Node; use Cache; my $cache=new Cache; sub new { ## blah blah $self; } sub get { my $self=shift; my $id=shift; if (my $data=$cache->check($id)) { return $data; } ## blah blah } 1;
This is wonderful until I converted the app to work under mod_perl. Now I can't figure out a way of maintaining a single cache for all instances.
Using use vars qw($cache) is fine to preserve the dynamic nature of $cache, but it keeps the $cache object alive across invocations of CGI (which is A Bad Thing because another thread might have modified the object and this instance has no knowledge of it).
What I want is for $cache to behave like it would under a normal CGI; it's created at the beginning of the execution of the script and dies at the end.
If this was in the main cgi-bin and not a class, I could do something like:
But this won't work inside a module (because mod_perl only executes the class once when loading it for the first time).{ $cache=new Cache; } ## everything { undef $cache; }
Assuming this was moderately understandable (which I doubt), does anyone have any suggestions or ideas?
In reply to Regarding variables that by mr.nick
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |