On Aug 17, 2005, at 2:28 PM, Ingo Blechschmidt wrote:

Stevan Little wrote:
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

hm, I've thought of these as follows:

    class Foo {...}    # is really
    class Foo {
        my $?CLASS := Foo;

    method bar($self:) {...}   # is really
    method bar($self:) {
        my $?SELF := $self;

Yes, this is how I saw it too.

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?

I think so, too.

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'd opt for yes.

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

role, submethod?

I think in a Role, $?SELF would still be the invocant in a method, and $?CLASS would (eventually) bind to the class the role was composed into.

As for submethods, I see them like this:

submethod foo () { ... }

is really ..

submethod foo () {
        next METHOD unless $?SELF ~~ $?CLASS;

At least that is how larry explained to me about a month ago.



Linux, the choice of a GNU | Mathematicians practice absolute freedom.
generation on a dual AMD   | -- Henry Adams
Athlon!                    |

Reply via email to