Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I shot myself in the foot (but only slightly) the other day and thought I'd share with you all.

I was testing a piece of code something like:

my $foo = $obj->foo() or die; my $bar = $foo->bar() or die; ... baz() or die; my @quux = $bar->quux(); for my $quux (@quux) { ... }
but many of the classes and subs called were not available. So I thought: no problem, I'll wrap a test framework around the code that provides a sub quux to return sample data and a sub AUTOLOAD to make sure things that need to return true. Since some of the things that need to return true are constructors, I'll make it sub AUTOLOAD { bless {} }.

And I got it running; the real subs that existed got called; the sub quux that provided fake data got called; everything else was effectively a noop. But there was a problem with the output, and I needed to run it in the debugger, and ran into a mystery that stumped me for a little while. You can try it yourself; run perl -d -we'sub AUTOLOAD { bless {} } foo()' and note that "s" stepping into foo seems ineffective; you can do it over and over again without terminating. And using "n" gets you a "100 levels deep in subroutine calls!" warning.

In retrospect, the problem was simply solved by an additional sub declaration:


In reply to AUTOLOAD mystery by ysth

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 musing on the Monastery: (4)
As of 2024-04-23 22:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found