2008/6/21 Ovid <[EMAIL PROTECTED]>: > > --- Hans Dieter Pearcey <[EMAIL PROTECTED]> wrote: > >> > never does anything to the importing package >> > >> > use Foo::Bar as => Bar; >> > >> > plops a constant function Bar into your package. The constant is an >> > object on which you can do >> > >> > Bar->some_function(@args) >> > >> > and it is the equivalent of calling >> > >> > Foo::Bar::some_function(@args) >> >> In my TODO is an entry for implementing this for Sub::Exporter. >> >> You don't even need to use AUTOLOAD: >> >> * create Some::Long::Generated::Package >> * import symbols from Foo::Bar into SLGP, wrapping each with >> sub { shift; $original_code->(@_) } >> * export Bar() into the calling package >> sub Bar () { "Some::Long::Generated::Package" } > > This is sort of on the CPAN now. > > use aliased 'Some::Long::Module::Name::For::Customer'; > my $customer = Customer->new;
That does it for OO modules which would cover a lot but not for functions which is where the evil of default exports really kicks in. I wrote the code this evening to make use pi X::Y::Z as A; A->foo(1) # same as X::Y::Z::foo(1) work as I was suggesting. It's a fair bit of symbol poking but nothing terribly clever. Unfortunately, I've just realised that it restricts you to functions, you can't abbreviate X::Y::Z->method() with this. I suppose people shouldn't be mixing the two but it's annoying. I can't see any way around that limitation besides also using aliased and giving it two distinct short names. http://www.fergaldaly.com/computer/pi/ I won't put it on CPAN because I'm not serious about it, if someone else wants to use the code, feel free, F > It's moderately popular and people are quite happy with it (at least > from the feedback I've gotten). Though I'm rather interested in this > take on the idea. > > Cheers, > Ovid > > -- > Buy the book - http://www.oreilly.com/catalog/perlhks/ > Personal blog - http://publius-ovidius.livejournal.com/ > Tech blog - http://use.perl.org/~Ovid/journal/ > Official Perl 6 Wiki - http://www.perlfoundation.org/perl6 > Official Parrot Wiki - http://www.perlfoundation.org/parrot >