Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I thought this was too simplistic a question for SoPW, but the CB was pretty well engaged in an interesting discussion that I decided trying to interrupt further would be rude :)

I have an existing code-base, and I want to begin writing a test suite for one of the modules. I've decided that the best way to start would be to determine exactly what data is being passed into each subroutine and what is getting returned.

So, for example, I want to be able to specify that all method and subroutine calls in module Foo::Bar get logged, complete with a dump of the passed arguments and the returned data. This has to be done without modifying any existing code. (Adding a single 'use' at the top of the main script is acceptable, though)

I found Debug::Trace which looks like it will do the job, and the author looks like someone who knows his stuff (He also wrote the venerable Getopt::Long!) but I wonder if there is a better, more fitting solution to which the wisdom of the Monks can illuminate.

Update: Down the rabbit hole we go... I've now tried Debug::Trace, Devel::TraceCalls, and Devel::TraceMethods, and none worked... BUT I have an idea why.

The module that *uses* the module whose methods I want to trace is loaded dynamically, at run-time through a mechanism I created with an eval. In other words, the methods that call the methods I want to analyze are in a module that isn't used until run-time, and therefore the module containing the methods I want to analyze is not loaded until run-time. Ick...

It's a bit complicated to describe - the code is on CPAN as TL1ng. (please don't take this as a plug for my module... it's still young and fragile.)


Update 2: Eureka! Since I am testing, I already know which module will be loaded at run-time... so I can pre-load it and now Debug::Trace works!
perl -MTL1ng::Base -MDebug::Trace=TL1ng::Parser::parse_string,:indent\ +(2\),:nomaxdepth,:nouseqq test_simple_auto.pl

Of course, it would still be nice to get some more feedback on other better/best/interesting debugging techniques of similar ilk!

Ikegami - Even though I figured it out before you posted, Thank you!

In reply to [Solved] Best method of call tracing, without writing code? by Hercynium

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-24 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found