In Perl6, I suspect you'll solve this problem with code something like:
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).my $ArrayList= use Perl::Util::ArrayList; my $a= $ArrayList->new();
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):
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).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 );
And, although Perl5 doesn't support my $x= use ..., it does support (but doesn't document) the following rather neat trick:
via a module like, for example:my $factory= require My::Object::Module;
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. - tyepackage My::Object::Module; # ... sub factory { # ... } # ... \&factory; # a 'true' value
In reply to Re: Pragma (more) like Java's 'import'? (yes!)
by tye
in thread Pragma (more) like Java's 'import'?
by djantzen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |