How to "use" multiple modules with one "use"?

Viewed 3039

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 Func2);

I don't want repeat myself in every module, so looking for a way how to make one package e.g. My::Common what will contain the above packages and in my programs do only:

use My::Common;
say Func1("hello"); #say enabled and Func1 imported in the My::Common

how to achieve this?

The was read preldoc -f use and perldoc perlmodlib so i think I must "somewhat" to do this with BEGIN plus require&import, but absolutely don't know how.


UPDATE: I'm already tried the basic things.

With require - my prg.pl program.

require 'mymods.pl';
$var = "hello";
croak "$var\n";

mymods.pl contain

use strict;
use feature 'say';
use Carp qw(carp croak cluck);
1;

DOES NOT WORKS. Got error:

$ perl prg.pl 
String found where operator expected at prg.pl line 3, near "croak "$var\n""
    (Do you need to predeclare croak?)
syntax error at prg.pl line 3, near "croak "$var\n""
Execution of prg.pl aborted due to compilation errors.

with "use My":

use My;
$var = "hello";
croak "$var\n";

my My.pm

package My;
use strict;
use feature 'say';
use Carp qw(carp croak cluck);
1;

DOES NOT WORKS either. Got the same error.


Any working idea?

3 Answers
Related