A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://perldoc.perl.org/functions/__CLASS__ below:

__CLASS__ - Perldoc Browser

#__CLASS__

Invoked within a method, 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 ref($self) 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 __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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4