=over
=item __CLASS__
X<__class__>
Invoked within a L|/method NAME BLOCK>, or similar location, such as
a field initializer expression, this token returns the name of the class of
the invoking instance. Essentially it is equivalent to C[ except
that it can additionally be used in a field initializer to gain access to
class methods, before the instance is fully constructed.
use feature 'class';
class Example1 {
field $f = __CLASS__->default_f;
sub default_f { 10 }
}
In a basic class, this value will be the same as
L|/__PACKAGE__>. The distinction can be seen when a subclass
is constructed; it will give the class name of the instance being constructed,
rather than just the package name that the actual code belongs to.
class Example2 :isa(Example1) {
sub default_f { 20 }
}
my $obj = Example2->new;
# The $f field now has the value 20
=back]