Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Which subroutine or method was called?

by QM (Vicar)
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?

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

Comment on Which subroutine or method was called?
Select or Download Code
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

Re: Which subroutine or method was called?
by toolic (Chancellor) 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 (Priest) 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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-12-19 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (74 votes), past polls