Diddling @INC, order of entries in it

Ovid publiustemp-londonpm at yahoo.com
Wed Aug 1 20:10:37 BST 2007


--- Adriano Ferreira <a.r.ferreira at gmail.com> wrote:

> I could not override "do" either (using CORE::GLOBAL::do). I don't
> know where to find the list of overridable builtins, but maybe "do"
> is not among them.

To determine if something is overrideable, you can use the prototype
function:

  prototype FUNCTION
    Returns the prototype of a function as a string (or "undef" if
    the function has no prototype).  FUNCTION is a reference to, or
    the name of, the function whose prototype you want to retrieve.

    If FUNCTION is a string starting with "CORE::", the rest is
    taken as a name for Perl builtin.  If the builtin is not over-
    ridable (such as "qw//") or its arguments cannot be expressed
    by a prototype (such as "system") returns "undef" because the
    builtin does not really behave like a Perl function.  Other-
    wise, the string describing the equivalent prototype is
    returned.

In other words, if 'prototype "CORE::do"' returns undef, you cannot
override do.

  ~ $ perl -MData::Dumper -le 'print Dumper prototype "CORE::do"'
  $VAR1 = undef;
 
  ~ $ perl -MData::Dumper -le 'print Dumper prototype "CORE::die"'
  $VAR1 = '@';

However, aliasing it to an overridden CORE::GLOBAL::Require seems to
work:

  #!/usr/bin/perl -l

  use strict;
  use warnings;

  BEGIN {
    *CORE::GLOBAL::require =
      sub (*) { die "Death *is* an option for @{[shift]}" };
    *CORE::GLOBAL::do = *CORE::GLOBAL::require;
  }

  foreach my $stuff ( "use Fun", "do 'something'" ) {
    eval $stuff || print $@;
  }

That prints out:

  Death *is* an option for Fun.pm at over.pl line 8.
  BEGIN failed--compilation aborted at (eval 1) line 2.

  Death *is* an option for something at over.pl line 8.

What have I misunderstood?  Is this a bug?

Cheers,
Ovid

--
Buy the book  - http://www.oreilly.com/catalog/perlhks/
Perl and CGI  - http://users.easystreet.com/ovid/cgi_course/
Personal blog - http://publius-ovidius.livejournal.com/
Tech blog     - http://use.perl.org/~Ovid/journal/


More information about the london.pm mailing list