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

How can we obtain the attributes of a built-in function?

It is possible to check their prototypes as if they were ordinary subs through CORE, and they can be overridden by ordinary subs through *CORE::GLOBAL, but I have not found a way to apply attributes::get() to a built-in function or variable. Is that even possible?

The issue seems as important as prototype for overriding Perl's built-in functions.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Built In Attributes
by jryan (Vicar) on Jul 17, 2003 at 18:50 UTC

    Are you simply trying to check for attributes on builtins, or install attributes onto builtins? I'm not sure how you could apply an attribute to a builtin, but perhaps you could try something similar to what Hook::LexWrap does. First, alias the function (in this case, the builtin) to some anonyomous name, and then repoint the builtin's glob entry in the symbol table to some new closure (the closure would simply call the builtin with its new anonymous name). You could then apply attributes to the closure, and still call the builtin in the same way.

    I might have missed the point, and if I have, could you explain in more depth what you are trying to do? :)

      I simply want to read the list of their attributes, if possible.

      When I try calling get('substr'), or some fully qualified name, perl throws Usage: attributes::get $ref at -e line 1. If I do the dubious \&CORE::substr the error goes away, but no attributes are found - unsurprising since calling builtins that way doesn't work either.

      After Compline,
      Zaxo

        Most builtins don't have attributes. The only ones I can think of are:

        • substr - lvalue
        • pos - lvalue
        • vec - lvalue

        So, unless I'm mistaken, there's your list. :)