Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Which subroutine or method was called?

by QM (Parson)
on Oct 09, 2012 at 12:00 UTC ( #997996=perlquestion: print w/replies, xml ) Need Help??
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?

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?

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

      Quantum Mechanics: The dreams stuff is made of

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://997996]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-06-22 05:59 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (121 votes). Check out past polls.