I realised you were looking for callbacks, but given the number of questions here that are of the form "I want to do X, here's my solution for Y - what's wrong?"
Indeed, "X-Y", it's called...

Actually it would have been more cleaner if I had called them callbacks from start, which I didn't for it simply didn't occur to me it was the right term, even though of course I knew about it having read it e.g. in Tk's docs.

However, in certain cases, I want access to variables that I don't want generic access to - or, perhaps, I can't have generic access to. So I put it my own closure:
my @strings = $self->expand_string($foo, sub { /^VAR1$/ && return $blah; /^VAR2$/ && return @some_list; $self->expand_variable() } );
Another interesting technique: seems obvious now that you point it out, but just like most obvious things one can easily overlook it...
So, from here, there's another minor point I would make with the code you started with: rather than passing in the variable, is it unreasonable to use $_? You may notice my expand_string code does that with do {local $_ = $var; $self->$func()}.
Yes and no: although I try to take advantage of Perl's topicalization as often as possible in conjunction with builtins, but for some reason I am not so keen on doing so with subs I write myself; however I have no argument against doing so, I simply generally don't feel like following this approach systematically...

In reply to Re^4: Seeking advice for OO-related strategy by blazar
in thread Seeking advice for OO-related strategy by blazar

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.