Ignoring whether "you should be doing this"; here's one way it could be done:
The PM file:
package MyObjs; use strict; use warnings; use enum qw[ :MOError=0 One Two Three Four Five ]; sub import { my $self = shift; my $caller = caller(); for( @_ ) { if( /^:MO/ ) { no strict; no warnings; *{ "$caller\:\:MOError$_" } = *{ "MOError$_" } for qw[ One + Two Three Four Five ]; } elsif( /^:O1/ ) { no strict; no warnings; *{ "$caller\:\:O1Error$_" } = *{ "Object1\:\:O1Error$_" } +for qw[ One Two Three Four Five ]; } elsif( /^:O2/ ) { no strict; no warnings; *{ "$caller\:\:O2Error$_" } = *{ "Object2\:\:O2Error$_" } +for qw[ One Two Three Four Five ]; } else { die "Unknown export $_"; } } } package Object1; use enum qw[ :O1Error=100 One Two Three Four Five ]; package Object2; use enum qw[ :O2Error=200 One Two Three Four Five ]; 1;
And a script that imports from that:
#! perl -slw use strict; use MyObjs qw[ :MO :O1 :O2 ]; print for MOErrorOne, O1ErrorThree, O2ErrorFive; __END__ C:\test>t-MyLib.pl 0 102 204
NOTE: The use of the enum module is not germane to this working. Any subs can be exported including normal subs and those generated by constant etc.
In reply to Re: How to export multiple packages in one file to another Perl program?
by BrowserUk
in thread How to export multiple packages in one file to another Perl program?
by Wcool
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |