Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Any way to inherit constants?
by Zaxo (Archbishop) on May 15, 2005 at 05:13 UTC | |
by Anonymous Monk on May 15, 2005 at 05:29 UTC | |
by thcsoft (Monk) on May 15, 2005 at 12:33 UTC | |
|
Re: Any way to inherit constants?
by bart (Canon) on May 15, 2005 at 08:52 UTC | |
|
Re: Any way to inherit constants?
by tlm (Prior) on May 15, 2005 at 14:26 UTC |