Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
If you want a goto because you don't want to continue in your existing function any more, then that means you want a return:
return $self->myFunction;
If you really do want a code ref which allows you to make use of $self, then you can create one with sub:
# Pick a method, wrap it up an a coderef and return it sub method_chooser { my $self = shift; return (rand % 2) : ? sub { $self->runAlice; } : sub { $self->runCha +rlie }; } sub do_stuff { my $self = shift; # Dunno what the chooser will choose my $code_ref = $self->method_chooser(); # But run it all the same $code_ref->(); }
Note that method_chooser will return a coderef which stores ('closes over') the value of $self. i.e. it will keep a reference to your object. This is handy, but it obviously counts as a reference for reference counting purposes, i.e. you can get a ref loop that way (and the consequent memory leak).

In reply to Re: oo code ref by jbert
in thread oo code ref by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and a log crumbles through the grate...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (6)
    As of 2017-10-22 06:49 GMT
    Find Nodes?
      Voting Booth?
      My fridge is mostly full of:

      Results (272 votes). Check out past polls.