Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Capitalized subroutine names and packages

by ihb (Deacon)
on Jan 06, 2003 at 00:16 UTC ( [id://224493]=note: print w/replies, xml ) Need Help??


in reply to Capitalized subroutine names and packages

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:
use Test; Tset::->can('can'); # Bareword "Tset::" refers to nonexistent package ...
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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://224493]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-24 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found