Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Redefining Imported Subs: of scope and no

by ikegami (Pope)
on Feb 11, 2013 at 06:10 UTC ( #1018100=note: print w/ replies, xml ) Need Help??


in reply to Redefining Imported Subs: of scope and no

How do I dynamically redefine imported subroutines?

That's actually quite easy, but say is not being imported; it's not even a subroutine! say is an operator, and use feature 'say'; merely controls whether the compiler recognises it or not. (It always recognises CORE::say, though.)

Some operators can be overridden from within Perl by overriding GLOBAL::CORE::op, and some can't. The following checks whether say can be overridden this way:

>perl -E"say defined(prototype('CORE::say')) ?'yes':'no'" no

Its funky syntax doesn't permit it.

say say LIST say FILEHANDLE LIST say BLOCK LIST

It could be done using a CallChecker, but that involves dropping to C/XS.


Comment on Re: Redefining Imported Subs: of scope and no
Select or Download Code
Re^2: Redefining Imported Subs: of scope and no
by LanX (Canon) on Feb 11, 2013 at 10:08 UTC
    > ... merely controls whether the compiler recognises it or not. (It always recognises CORE::say, though.)

    Not always, at least for me, with which version did you check?

    lanx@nc10-ubuntu:~$ perl -e 'CORE::say("bla")' CORE::say is not a keyword at -e line 1. lanx@nc10-ubuntu:~$ perl -E 'CORE::say("bla")' bla lanx@nc10-ubuntu:~$ perl -version This is perl, v5.10.0 built for i486-linux-gnu-thread-multi

    > say is an operator, and use feature say; merely ...

    As a minor nitpick, according to the definitions in perlglossary I'd rather use built-in and not operator to describe say, though the differences are indeed fuzzy.

    Cheers Rolf

      Not always, at least for me, with which version did you check?

      It apparently went missing until 5.16.

      As a minor nitpick, according to the definitions in perlglossary I'd rather use built-in and not operator to describe say, though the differences are indeed fuzzy.

      Builtin functions are a slight superset of what both perlop and perlfunc call list operators and named unary operators. say is a builtin because say is a list operator. (It's fuzzy which builtins aren't operators.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (18)
As of 2014-08-01 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (25 votes), past polls