Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: work around for static vars and singleton constructors not inheriting properly?

by simonm (Vicar)
on Jul 18, 2005 at 16:07 UTC ( #475797=note: print w/ replies, xml ) Need Help??


in reply to work around for static vars and singleton constructors not inheriting properly?

Sorry for the late reply, but I don't think Class::MethodMaker will do this for you.

My Class::MakeMethods module does have something close to what you want:

use Class::MakeMethods::Template::ClassVar 'instance' => 'my_singleton', 'scalar' => 'my_static';

Those methods store a value in a per-class package variable, so each subclass and its instances share a common value without influencing the superclass and other subclasses.

For the static method, if you'd like the subclasses to default to sharing the superclass value and only override it in a few specific subclasses, use Template::Inheritable instead of Template::ClassVar.

I haven't tested the combination of Template::ClassVar and instance; please let me know if it doesn't work as expected...

  • Comment on Re: work around for static vars and singleton constructors not inheriting properly?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://475797]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2016-06-30 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (403 votes). Check out past polls.