How to “use” multiple modules with one “use”?

前端 未结 3 1935
遇见更好的自我
遇见更好的自我 2020-12-09 19:18

I want use some packages and some pragmas in all my programs, like:

use 5.014;
use warnings;
use autodie;
use My::ModuleA::Something;
use ModuleB qw(Func1 Fu         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 20:07

    It's actually fairly simple, if you override your "common" module's import method. See the source of chromatic's Modern::Perl module for an example of exporting pragmas.

    For re-exporting things defined in other modules, I seem to recall that $export_to_level (see the Exporter docs, although it's not explained all that clearly) should do that, although I can't find any good examples at the moment. Another option would be Pollute::persistent, although I haven't used it, don't know anyone else who's used it, and can't say how stable/solid it's likely to be. If it works, though, it's probably the quickest and easiest option.

提交回复
热议问题