CLASS - Alias for __PACKAGE__ |
CLASS - Alias for __PACKAGE__
package Foo; use CLASS;
print CLASS; # Foo print "My class is $CLASS\n"; # My class is Foo
sub bar { 23 }
print CLASS->bar; # 23 print $CLASS->bar; # 23
CLASS and $CLASS are both synonyms for __PACKAGE__. Easier to type.
$CLASS has the additional benefit of working in strings.
CLASS is a constant, not a subroutine call. $CLASS is a plain variable, it is not tied. There is no performance loss for using CLASS over __PACKAGE__ except the loading of the module. (Thanks Juerd)
Michael G Schwern <schwern@pobox.com>
perlmod(1)
CLASS - Alias for __PACKAGE__ |