"It depends". this is the correct answer. Actually a relatively simple package name; usually you will have an instance or class name to start with. However, there are times when you really need the package name - __PACKAGE__ - this is obviously a tool for this work that is superior to the literal one. Here are some suggestions:
Never call off __PACKAGE__ methods inside methods, as this makes it impossible for the heirs to modify your implementation by simply overriding the called method. Use $self or $class instead.
Try to avoid __PACKAGE__ inside methods in general. Each use of __PACKAGE__ adds a bit of inflexibility. Sometimes inflexibility is what you want (because you need permission at compile time or have poor control over where the information is stored), but be sure that what you want is worth it. You will thank yourself later.
Outside of methods, you do not have access to $self and must call off __PACKAGE__ methods, not a literal. This is mainly important for compile-time declarations, similar to those provided by Class::Accessor .
darch
source share