Welcome to the Monastery | |
PerlMonks |
Re: Capitalized subroutine names and packagesby ihb (Deacon) |
on Jan 06, 2003 at 00:16 UTC ( [id://224493]=note: print w/replies, xml ) | Need Help?? |
This is exactly the reason why I append :: to at compile-time known package names. By doing Bar:: instead you can be sure that it won't resolve to anything unintended.
Using tailing :: has another indirect advantage. For a person like me that makes typos every now and then it can be nice to be given "stricture" on package names. The following code will emit a warning: Being consistent with this I also quickly spot dynamically loaded modules, something that sometimes can be quite useful. Tailing a pair of colons isn't something special for method invocations. If you wish to save a class/package name in a variable you can use this too: my $class = Foo::Bar::;. Agreed, the ::; hurts your eyes, but then again, I consider that a good thing in this case. (As merely a parenthesis the indirect object syntax can be pointed out. Since you hopefully don't use this when you really shouldn't, it's likely you won't have to deal with this, but anyway. new Foo (1) x 3 is almost equal to Foo->new(1) x 3. new Foo:: (1) x 3 is equal to Foo::->new((1) x 3). sub Foo { 1 } new Foo; blows up.) Hope I've helped, ihb
In Section
Meditations
|
|