Hi,

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
> exception?

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;
        ...;
    }

> 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
> of.

role, submethod?


--Ingo

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

Reply via email to