It sounds like you want to import all symbols from a package into the current package. You can use a small module like this:
package Exporter::All; sub import { my @packages = @_; shift @packages; @packages = (caller)[0] unless defined @packages; foreach my $orig (@_) { *{"${orig}::import"} = sub { my $pkg = (caller)[0]; foreach (grep {!/^import|__ANON__|BEGIN|END$/} keys %{"${orig}::"}) { if (defined *{"${pkg}::$_"}) { warn "Warning: symbol $_ already defined in $pkg." } else { *{"${pkg}::$_"} = *{"${orig}::$_"}; } } } } } 1;
And then use it like this:
package Foo::Bar::Baz; use Exporter::All; sub x {print 1}; # ... package main; use Foo::Bar::Baz; x();
Or like this:
package Foo::Bar::Baz; sub x {print 1}; # ... package main; use Exporter::All qw(Foo::Bar::Baz); x();
In reply to Re: Pragma (more) like Java's 'import'?
by jryan
in thread Pragma (more) like Java's 'import'?
by djantzen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |