Hello all,

I tried to search for this answer in AES12, but I did not see anything, and a perl6.lang search just brought up the whole $_.method vs. ./method debate (which was too much to shlog through).

So, onto my question, I am wondering what are the valid scopes for $?SELF and $?CLASS.

Are these (magical) globals who only have bound values in certain contexts? If that is so, what value do they have outside of a valid context? undef? or is attempting to accessing the value a runtime exception?

Or ...

Is it a syntax error to access them outside of a valid scope, and therefore caught at compile time? In this case, then it seems to me that they are not behaving as global variables so much as they are behaving like language keywords.

Now as for the valid contexts.

The obvious one is that they are both valid within a method. I asumme that $?SELF is bound to the invocant, and $?CLASS is bound to the class the method was defined within. It seems to me that this also mean that in a class method, that $?SELF == $?CLASS?

Also (IIRC) we discussed $?CLASS being valid inside a class Foo { ... } block at the hackathon. Would mean that something like this should be possible.

  class FooLoggerProxy is Foo {
      has Logger $.logger;
      for ($?CLASS.meta.superclasses()) -> $super {
          for ($super.meta.getmethods()) -> $method {
             $?CLASS.meta.add_method($method.label => method {
                  $?SELF.logger.log($method.label ~ " has been called");
                  return $method.do([EMAIL PROTECTED])

I am not sure if there are any other valid contexts other than inside a method or a class composition block. At least none that I can think of.



Reply via email to