in reply to Inheriting constants in the same file -- help me find a better way!
Call that Import.pm. And then the following little test script shows it in operation:package Import; sub import { shift; # I don't care about my package. my $to_call = shift; my $call_from = caller; eval qq( package $call_from; # So the import goes into the right package. $to_call\->import(\@_); ); } 1;
OK, so you still have to put the definition of what you are willing to export into a BEGIN block. But that is one block, one place. If that bugs you, take a page from base and write a module that will set your @EXPORT and @EXPORT_OK for you in its import method.package Foo; BEGIN { use base Exporter; @EXPORT = "HELLO"; @EXPORT_OK = "BYE"; } use constant HELLO => "Hello, world\n"; use constant BYE => "Goodbye, cruel world\n"; package Bar; use Import "Foo"; print HELLO; package Baz; use Import qw(Foo BYE); print BYE;
|
|---|