Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Module Naming Dilemma

by Anonymous Monk
on Jan 06, 2005 at 16:48 UTC ( [id://419985]=note: print w/replies, xml ) Need Help??


in reply to Module Naming Dilemma

Why not just use a GLOB reference alias?. This will make package Bar works as an alias for Foo:
*Bar:: = \*Foo:: ;
Here's a sample:
package Foo ; sub new { bless {} } sub test { print "TEST> [@_]\n" ; } package main ; *Bar:: = \*Foo:: ; my $foo = Foo->new() ; $foo->test(123) ; print "$foo\n" ; my $bar = Bar->new() ; $bar->test(456) ; print "$bar\n" ;
Output:
TEST> [Foo=HASH(0x1a4ece4) 123] Foo=HASH(0x1a4ece4) TEST> [Foo=HASH(0x15d53dc) 456] Foo=HASH(0x15d53dc)

Replies are listed 'Best First'.
Re^2: Module Naming Dilemma
by Ven'Tatsu (Deacon) on Jan 06, 2005 at 18:26 UTC
    Doing that you have altered the global namespace. If you were to use this in a module then some one could potentialy overwrite another class used in their code or in another module without ever knowing it. Ovid's and gaal's ideas are both compleatly isolated.
    In short your begging to get bit by this code if it's used in production.

Log In?
Username:
Password:

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

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

    No recent polls found