Here's one approach
package deprecated; use Carp qw/ carp croak /; use vars '%subs'; sub import { my($good_self, @subs) = @_; my $pkg = caller; *{"$pkg\::AUTOLOAD"} = sub { croak "unknown subroutine '$AUTOLOAD'" unless exists $deprecated::subs{$AUTOLOAD}; carp "deprecated subroutine '$AUTOLOAD'"; *$AUTOLOAD = $deprecated::subs{$AUTOLOAD}; goto &$AUTOLOAD; } unless defined &{"$pkg\::AUTOLOAD"}; for(@subs) { $subs{"$pkg\::$_"} = \&{"$pkg\::$_"}; *{"$pkg\::$_"} = *{"dummy_$pkg\_$_"}; } } q[ the end is nigh ... ];
And some example usage
{ package foo; sub func1 { print "old\n" } sub func2 { print "older\n" } sub func3 { print "new\n" } use deprecated qw/ func1 func2 /; } print "calling: func1\n"; foo->func1; print "calling: func2\n"; foo->func2; print "calling: func3\n"; foo->func3; print "calling: func1 again ...\n"; foo->func1; __output__ calling: func1 deprecated subroutine 'foo::func1' at deprecated_test.pl line 13 old calling: func2 deprecated subroutine 'foo::func2' at deprecated_test.pl line 15 older calling: func3 new calling: func1 again ... old
Note that use deprecated goes after the subroutine declarations, so they're populated when it goes to insert the dummy routines.

Briefly, what it does is create an AUTOLOAD method that will carp and then replace the dummy subroutine with the actual subroutine.

HTH

_________
broquaint


In reply to Re: use deprecated; by broquaint
in thread 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.