|Syntactic Confectionery Delight|
use deprecated;by halley (Prior)
|on Nov 26, 2003 at 14:40 UTC||Need Help??|
halley has asked for the
wisdom of the Perl Monks concerning the following question:
I'm thinking of putting together a basic developer aid for my workplace, a pragmatic module called deprecated. The idea is to detect when a user is probably a developer, and caution the user that they're depending on a deprecated module or symbol.
(In our facility, we have many environment variables which could hint to a script that it's being executed by a developer, and not by a typical end-user. If you have other more general ideas to detect this situation, that's a side question.)
For a wholly-deprecated module, I would just add one line to the top of the module. Then when the top-level script is executed in a developer environment, deprecated::import() would simply carp about how OldeCruft is deprecated. The deprecation is just a warning; no changes are made to the rest of the behavior.
However, I'd also like to be able to deprecate specific symbols within the crufty namespace, without editing anything else deep in OldeCruft.pm. For example, if OldeCruft::dangerous() is deprecated, then the script should carp about that fact on the FIRST call to that sub.
Is there a straightforward and robust way to hook each named deprecated sub with a separate check-and-carp behavior? I'm not too familiar with the way sub names are joined to a symbol hash, and want to know if manipulating that symbol hash is a risky or generally safe proposition.