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.

package OldeCruft; use deprecated; # carps if module loaded ...

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.

package OldeCruft; use deprecated qw(dangerous); # carps if OldeCruft::dangerous() is called ...

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.

Update: use deprecated; contains the tested and documented implementation, from Aristotle's suggestions.

--
[ e d @ h a l l e y . c c ]


In reply to use deprecated; by halley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.