You did all this to avoid typing a couple of arrows? I think your lazy-meter is going in the wrong direction here.

Well, it's not the arrows that bother me, just the number of keystrokes. Especially during testing I tend to have a debug call almost every other line, so they do add up.

But you're probably right that convenience now is not worth the extra maintenance headaches my convoluted solution would cause.

In short, putting an object into a global variable is only a good idea if you want a singleton.

The way I did it I don't think the global scope of that global variable will ever contain an object, so I wasn't too worried about that part

Also, use of local() is kind of a last resort these days. I use it in a couple of situations where it's dramatically easier than the alternative, but there aren't many of those. It's likely to trip you up at some point.

Using my obviously wouldn't work since debug wouldn't be able to get to it, and I think just omitting the local would cause re-entrancy issues. So local seemed like the only solution.

You could easilly simplify to $self->debug($text) with no risk, just by making a debug() method that calls $self->{'debug'}. If you really want the debug code ref to differ by object, that's as good as you're likely to get without doing risky things.

I thought of doing that but didn't think it went far enough.

Based on your reply, I think I'll settle on using $self->debug() because of the extra flexibility over the $self->{'debug'}->() call, and just adding a shortcut to my editor to paste it into the code.

Thanks for knocking some sense into me :)


In reply to Re^2: Short invocation for per-object methods by Crackers2
in thread Short invocation for per-object methods by Crackers2

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.