Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Overloaded *CORE:: function not behaving correctly

by broquaint (Abbot)
on Jul 29, 2004 at 02:53 UTC ( [id://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
HTH

_________
broquaint

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.
      HTH

      _________
      broquaint

        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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-16 06:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found