http://www.perlmonks.org?node_id=997996

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

I'm having a funny problem, and suspect that my uses are stepping on each other. How to determine which subroutine is actually getting called?

For instance:

use Time::HiRes qw(sleep); sleep(5);

This imports sleep over the builtin. How do I check that the sleep I call is the sleep I want?

And while we're at it, how to do the same for a method -- that is, I can say: $object->method();, but where does that method live?

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re: Which subroutine or method was called?
by toolic (Bishop) on Oct 09, 2012 at 12:19 UTC
    To remove all doubt, don't export any functions, then explicitly call the one from the Time::HiRes module:
    use Time::HiRes (); # prevents exporting any functions, although POD s +ays none are exported anyway Time::HiRes::sleep(5);
Re: Which subroutine or method was called?
by 2teez (Vicar) on Oct 09, 2012 at 13:50 UTC

    OR, you could use CORE to call bulitin like so:

    use strict; use warnings; use Time::HiRes qw(); # just like others said Time::HiRes::sleep(2); # module sleep function CORE::sleep(2); # bulitin sleep function
    Then to see what went down call your script like so perl -MO=Deparse perlscript.plthen you see this:
    use Time::HiRes (); use warnings; use strict 'refs'; &Time::HiRes::sleep(2); sleep 2;

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re: Which subroutine or method was called?
by Anonymous Monk on Oct 09, 2012 at 12:12 UTC
    $ perl -MDDS -MTime::HiRes=sleep -e " Dump\&sleep" $CODE1 = \&Time::HiRes::sleep; $ perl -MDDS -MTime::HiRes=sleep -le " print main->can(q/sleep/)" CODE(0x9a38ac) $ perl -MDDS -MTime::HiRes=sleep -e " Dump( main->can(q/sleep/) )" $CODE1 = \&Time::HiRes::sleep;

    Maybe see also module_info/pfunc

      DDS would be?

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

      Can't locate object method "ARRAY" via package "B::SPECIAL" at C:/stra +wberry/perl/site/lib/Data/Dump/Streamer.pm line 3698.

      This seems to be a (recurring?) bug. I see it also in Ubuntu 10.4, Perl 5.10.1, as well as the above Strawberry Perl 5.16.1.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of