In Perl6, I suspect you'll solve this problem with code something like:
my $ArrayList= use Perl::Util::ArrayList;
my $a= $ArrayList->new();
because Larry mentioned that he'd like to have
use return the package that was just created (I think he meant/said "package object" not "package name" but that doesn't really change the above code much).
In Perl5, I solve this problem by having the module be able to export a factory object (for OO modules) and by supporting aliasing of functions during export (for procedural modules):
my $Widget;
use My::Widget::Module( Factory=>\$Widget );
my $dumper;
use Devel::Peek( { Dump=>\&DumpSV } );
use Data::Dumper( { Dump=>\&Dumper } );
use My::Module( { Dump=>\$dumper } );
my $flange= $Widget->new();
$dumper->( $flange );
Dumper( $flange );
Note that you have to write your own
sub import to support the above (some of the newer replacements for
Exporter also support aliasing of imports, IIRC).
And, although Perl5 doesn't support my $x= use ..., it does support (but doesn't document) the following rather neat trick:
my $factory= require My::Object::Module;
via a module like, for example:
package My::Object::Module;
# ...
sub factory {
# ...
}
# ...
\&factory; # a 'true' value
The only thing I don't like about this trick (besides it being undocumented, though that didn't stop me from guessing that it might work) is that you can't pass in any arguments to
require like you can with
use.
-
tye