Perl: how to share the import of a large list of modules between many independent scripts?

后端 未结 5 881
梦如初夏
梦如初夏 2021-01-12 10:40

I have many standalone scripts. The only thing they share, is that they use() a large set of CPAN modules (that each export several functions). I would like to centralize th

5条回答
  •  孤城傲影
    2021-01-12 11:28

    Maybe more flexible than putting everything into main namespace would be to import into caller's namespace. Something like this:

    package SharedModules;
    
    sub import {
    
        my $pkg = (caller())[0];
        eval <<"EOD";
    
    package $pkg;
    
    use List::Util;
    use List::MoreUtils;
    
    EOD
    
        die $@ if $@;
    }
    
    1;
    

提交回复
热议问题