Whether that code is OK all depends on what happens to $object.

Note that potential problems with persistent data in mod_perl aren't limited to closures. All kinds of bugs can creep in if you're not taking the persistent nature of mod_perl into account. If you've done mostly CGI programming it can take a while to get comfortable with that, but it's really not much different from writing any other persistent program.

Detecting unintended closures may be a good thing, but I suggest you just use it in development and turn it off in production and in situations where you may actually want to use closures. That way you can write and test with all kinds of (inefficient) hand holding, and run the code with good performance when it's tested.

In any case, it's useful to have a good understanding of closures, firstly just because they're a very powerful tool, and secondly because if you know how closures work you're not very likely to make the kinds of mistakes you're detecting here.


In reply to Re^5: Catching closures by Joost
in thread Catching closures by bduggan

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.