Hi Monks,

Update: misunderstanding was somewhere else, this bit isn't the problem at all. Forget it!

I'm trying to understand what a bit of code is doing and I've got myself in a knot. In class A, there is a method that calls a class method of class B, with a code ref as an argument. Something like:

#in class A sub do_stuff{ my $self = shift; #1 Class::B->do_things(sub{ my $self = @_; #2 my $blah = Class::C->blah({ arg1=>$self->{blah}, #3 arg2=>self->{wibble} }) }) }
So, which class do the $selfs in the call to do_things actually refer to?
#1 - Class::A
#2 - Is this Class::B as the code is actually executed in the context of that class or is it Class::A - and if so, why?
#3 - does the $self->{blah} get interpolated in the context of Class::A before the code ref is even created, or is it still $self->{blah} in the code, in which case it will refer to whatever #2 means.

Thanks for any help!
Cass

</returns to banging head off desk>


In reply to code ref confusion by CassJ

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.