in reply to Re^2: Constants and Subclasses...
in thread Constants and Subclasses...

I understand this more fully now after sleeping over it and after your excellent explanation and alternative with use Parent; @ISA = 'Parent'. (But — in the single file case — realize I cannot use because that will call require which will try to read Parent from a file. In turn, use base apparently doesn't do this if it notices the package is already there — not relying only on %INC.)

With respect to the unwanted exportation of the constants, it might be better to implement this as suggested by jettero (Re^2: Constants and Subclasses...) and do:

our %EXPORT_TAGS = ( CONSTANTS => [qw(FOO)], # and other constants ); our @EXPORT_OK; Exporter::export_ok_tags('CONSTANTS'); # populate the @EXPORT_OK

and then

BEGIN { P->import(':CONSTANTS'); }

As the constants are not exported by default anymore, the user of the code should explicitly call for them or not.

Yeah, jettero, you were right from the beginning about the convenience of @EXPORT_OK and %EXPORT_TAGS.

Replies are listed 'Best First'.
Re^4: Constants and Subclasses...
by diotalevi (Canon) on Dec 19, 2006 at 17:47 UTC

    No... the most correct way to do this would be to use the normal class method syntax. This is OO so it's entirely likely that someone's going to want to subclass that constant at some point. Your static exporting circumvents inheritance.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊