It may be silly, but it seems that constants should come along with a base class just like methods. Consequently, I would like to access a superclass' constants without having to "use" a second file.
I looked at this question, but it doesn't float my boat. I guess if that's what exporter and constant are doing behind the scenes, it would be OK, but it is certainly non-intuitive.
So, what is the right way to inherit constants from a super-superclass?
Something along the lines of this:
# Foo/Constants.pm package Foo::Constants; use constant PI => 3; # Foo/Base.pm package Foo::Base; use Foo::Constants; # Foo/Sub.pm package Foo::Sub; use base "Foo::Base"; # Bar/Sub.pm package Bar::Sub; use base "Foo::Sub"; use strict; sub new { print PI; #fails, this is the one I want print Bar::Sub::PI; #fails print Foo::Sub::PI; #fails print Foo::Base::PI; #fails print Foo::Constants::PI #even this fails }
Of course, I could could "use Foo::Constants" in all those files, but, ideally, I would like to have a subclass of Foo::Constants (e.g. Bar::Constants) that would export even more things without having to re-export everything in it's superclass.
Thanks!
In reply to Any way to inherit constants? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |