Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Overloaded *CORE:: function not behaving correctly

by broquaint (Abbot)
on Jul 29, 2004 at 02:53 UTC ( #378274=note: print w/ replies, xml ) Need Help??

in reply to Overloaded *CORE:: function not behaving correctly

You have to override *CORE::GLOBAL:: functions at compile-time so when the parser sees them they're pointing to the right bit of code e.g

BEGIN { *CORE::GLOBAL::glob = sub { "glob overriden" }; } print glob('a pattern'), "\n"; *CORE::GLOBAL::join = sub { print "n/a" }; print join(' ', qw/ join not overridden /), "\n"; __output__ glob overriden join not overridden


Comment on Re: Overloaded *CORE:: function not behaving correctly
Download Code
Replies are listed 'Best First'.
Re^2: Overloaded *CORE:: function not behaving correctly
by leriksen (Curate) on Jul 29, 2004 at 05:52 UTC
    OK, both ysth and broquaint seem to be in agreement - you cant do it on the fly (ie like I did with a block-scope and a local operator) a CORE:: function. Looks like a separate test file that uses the BEGIN style is required

    Does anyone know why this is so (the design decision, not the fact), and where the pre-compile requirement is documented ?

    update s/can/cant/

    use brain;

      I believe this is so that builtins aren't looked up every time they are called, which is almost certainly for speed reasons. Where the fact that this 'builtin overriding behaviour needs to be implemented at compile-time' is documented, I'm not sure. It might be documented in the 3rd Camel, but I can't seem to find hide or hair of it in the standard docs. A patch to the Overriding Built-in Functions section of perlsub is probably needed.


        Second paragraph starts:
        Overriding may be done only by importing the name from a module at compile time--ordinary predeclaration isn't good enough.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://378274]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2015-10-07 09:15 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (175 votes), past polls