in reply to Re: Overriding built-in function works only via import()?
in thread Overriding built-in function works only via import()?

Consequently it shouldn't work if the import() is called in the same package, right? (Untested)

Hence the perldocs should be clearer:

> perlsub#Overriding-Built-in-Functions Overriding may be done only by importing the name from a module at compile time--ordinary predeclaration isn't good enough. 

A module is a .pm which supports importing with use It's normal practice to have its own package, but not necessarily so.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

  • Comment on Re^2: Overriding built-in function works only via import()?

Replies are listed 'Best First'.
Re^3: Overriding built-in function works only via import()?
by haukex (Archbishop) on Feb 02, 2018 at 10:02 UTC
    Consequently it shouldn't work if the import() is called in the same package, right? (Untested)

    Yep, looks like it:

    $ perl -wle '{ package Foo; sub import { *{caller."::readpipe"} = sub {"Foo"} } } BEGIN { Foo->import() } print `xyz`' Foo $ perl -wle 'sub import { *{caller."::readpipe"} = sub {"Foo"} } BEGIN { main->import() } print `xyz`' Can't exec "xyz": No such file or directory at -e line 2.