Re: Draft RFC: new pragma: C<use namespace>
[email protected] (Dave Storrs) Wed, 13 Sep 2000 11:07:02 -0700 (PDT)
| Newsgroups | perl.perl6.language.objects |
|---|---|
| Message-ID | <Pine.BSF.4.10.10009131046410.23329-100000@megazone23.bigpanda.com> |
On 13 Sep 2000, Piers Cawley wrote: > Hildo Biersma <[email protected]> writes: > > > Piers Cawley wrote: > > I'd like to use shorthands for A::B::C's Foo and X::Y::Z's Bar at the > > same time. > > Well you can't. The patch that I pinched this RFC from is a lexically How about if we added a list, @NAMES, into which you could assign namespace shortcuts, something like this: package main; push @NAMES, ("A::B::C" => 'ABC', "X::Y::Z" => 'XYZ', "StupidlyLongMathThingie" => "SLMT", "Bar::Baz" => "" ); ABC::do_stuff(); # prints "ABC"; XYZ::do_stuff(); # prints "XYZ"; SLMT::do_stuff(); # prints "4"; # do_stuff(); # [1] sub do_stuff() { print "main"; } package A::B::C; sub do_stuff() { print "ABC"; } package X::Y::Z; sub do_stuff() { print "XYZ"; } package StupidlyLongMathThingie; sub do_stuff() { print 2 + 2; } package Bar::Baz; sub do_stuff() { print "barbaz"; } __END__ Whenever the interpreter saw a namespace usage, it would need to check @NAMES in addition to checking the included modules list. The problem comes when the user aliases two different namespaces to the same alias (e.g., "Foobar" => "F", "Foxtrot" => "F") In this case, if the usage is unambiguous (e.g., F::do_foxtrot(), and the Foobar module does not contain a sub by that name), then perl should raise a warning but go ahead and execute. If the usage is ambiguous, this should be a fatal error. Dave