Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: use deprecated;

by Aristotle (Chancellor)
on Nov 26, 2003 at 17:53 UTC ( #310337=note: print w/replies, xml ) Need Help??


in reply to use deprecated;

That was nice food for thought.
package deprecated; use constant EVAL_CODE => <<'END_CODE'; sub %1$s::INIT { my $overridden = \&%2$s; *%2$s = sub { require Carp; Carp::carp('%2$s() is deprecated'); *%2$s = $overridden; goto &$overridden; }; } END_CODE sub import { my $class = shift; my $pkg = caller; eval join '', map sprintf(EVAL_CODE, $pkg, "$pkg\::$_"), @_; } 1;
It should be obvious what is happening here, if not just change the eval to a print.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^2: use deprecated;
by adrianh (Chancellor) on Nov 26, 2003 at 23:55 UTC

    Sneaky. Like it.

    You'd also need to check that the subroutine actually exists at INIT time, and wrap AUTOLOAD with something appropriate if it's defined.

    As liz points out this won't work in mod_perl, eval and other places where the INIT phase has already occured.

    I guess you could use a source filter to inline the wrapping code - but that would be really evil ;-)

      Actually, you don't even need to check whether the function exists. If you take a reference to a named but undefined function, it magically works once that function is defined. Perl is devious that way.
      #!/usr/bin/perl $_ = \&x; *x = sub { print "Oh my\n" }; $_->();
      This actually prints "Oh my".

      Makeshifts last the longest.

        Actually, you don't even need to check whether the function exists. If you take a reference to a named but undefined function, it magically works once that function is defined. Perl is devious that way.

        You're quite correct - I'm an idiot.

        In fact, I'm an idiot on two counts. My AUTOLOAD comment is equally bogus. Since everything is happening at INIT time the AUTOLOAD subroutine will already be defined.

        I restate my "sneaky" comment. Very nice :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://310337]
help
Chatterbox?
[ambrus]: erix: that one actually sucks. these days people should get rid of the old notion that TeX is the only thing you can use for decent mathematics writing, because MS Office and LibreOffice have reached the
[ambrus]: level where people can more easily write as good mathematical papers in them as the people who write bad LaTeX papers usually write.
[ambrus]: Yes, for like the first twenty of its years, TeX was basically the only system that allowed you to write decent maths papers, and C++ and PHP were programming languages that sucked, etc. But times change and people have to accept that.
Discipulus bad people + good tool < normal people + decent tool
[Discipulus]: php does not suck anymore?
[ambrus]: Discipulus: I'm not sure, but it certainly doesn't suck as much as it's used to. it's like C++, it sucks because people still recursively learn from twenty year old PHP examples,
[ambrus]: and they try to use the obsolete features that PHP has to support only for compatibility with old scripts. C++ and PHP both have the problem that people can't forget the past, because when they google "PHP" plus the problme they want to solve, they find b
[ambrus]: ad code examples.
[ambrus]: I'm not trying to recommend PHP, but I think it has way too bad a name because of its past.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2017-09-26 11:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (293 votes). Check out past polls.

    Notices?