Larry Wall wrote:
has $x; # private rw, no accessors, not virtual, name lexically scoped
has $_x; # private rw, rw _x accessor, not virtual, name class scoped
Even if I come across as intellectually handicapped but could
someone help me over this mental bridge: What is the difference
between these two scopes?
class Foo
{
#class scope starts here
has $x; # where does this go if not Foo::x
has $_y; # this goes into Foo::_y
# both $x and $_y can be used in code from here on
# and refer to the same two things respectively, right?
# or does class scope mean shared by all instances
# and lexically scopes per instance?
#class scope ends here
}
Other thinkings:
* Any self method can be called via $.x(@args) syntax, short for
$?SELF.x(@args).
Isn't & the code sigil?
* All roles can write completely private $x attributes that are not
visible outside their lexical scope but are nevertheless per-instance.
I understand that correctly, that $x in
role Foo { has $x = 7; method foo { $x++ } }
denotes a reference to an Item from the data environment of the object
that foo is invoked on. The type of the $?SELF that Foo is composed into
obviously is a subtype of Foo. What happens with this hidden payload if
the object changes its type such that it is no Foo anymore? E.g. by
undefining the slot &.Foo::foo?
Regards,
--
TSa (Thomas Sandlaß)