tlm has asked for the wisdom of the Perl Monks concerning the following question:

  1. Introspection

  2. Does Perl provide any way to programmatically list the "names" of all the Perl built-in functions? By "name" I mean the string, e.g. "y", that when appended to the string "CORE::" can be given to CORE::prototype as its argument to obtain the prototype of the corresponding Perl built-in.

  3. Overriding built-ins

  4. Some Perl built-ins are overridable, others aren't. What is the best way to find out which are the ones that cannot be overridden?

    For all non-overridable built-ins CORE::foo, the expression CORE::prototype('CORE::foo') returns undef, but the converse is not true. For example, CORE::prototype('CORE::system') returns undef, but CORE::system is overridable, as shown by the following snippet:

    use strict; use warnings; use subs 'system'; sub system { warn "this is not the real system\n" } warn "about to test system\n"; system 'date'; warn "done testing system\n"; __END__ about to test system this is not the real system done testing system
    For other built-ins with a CORE::prototype return value of undef, however, the above trick won't work. Either the overriding function will be silently ignored (as happens if one tries to override CORE::print), or Perl will react more spectacularly, such as seg-faulting if one tries to override CORE::require.

    So, is there a way to determine which built-ins are overridable, other than trial and error?

(Both questions prompted only by curiosity.)

the lowliest monk

Replies are listed 'Best First'.
Re: 2 Qs: introspection & overriding built-ins
by deibyz (Hermit) on Apr 12, 2005 at 08:06 UTC
    You can have a look at This node if you haven't done it yet. It has some interesting discussion about the topic, specially diotalevi's answer. It has some explanation about some internals where I get lost, but maybe you can get something clear. It also has a list of "not overridable functions".
Re: 2 Qs: introspection & overriding built-ins
by adrianh (Chancellor) on Apr 12, 2005 at 13:21 UTC
    Does Perl provide any way to programmatically list the "names" of all the Perl built-in functions?

    Not built in, but you may find B::Keywords of use.