Perl: can you use the "use" d module or set to include the script?
For example, each of my scripts has this at the top:
use warnings; use strict; use v5.10;
use Tools;
My Tools package has a lot of features that I use all the time. I'd rather just enable it and use warnings for it, strict and 5.10 to include the script, since I have to use
use the ones for each script. Is there a way to do this?
+3
source to share
1 answer
You can use Import :: Into with a custom method import
to include stuff in the import class. For example:
package Tools;
use strict;
use warnings;
use feature ':5.10';
use Import::Into;
sub import {
my $target = caller;
strict->import::into( $target );
warnings->import::into( $target );
feature->import::into( $target, ':5.10' );
# other imports, etc
}
I wrote a more detailed post on using Import :: Into here: Removing Perl Boilerplate with Import :: Into .
+4
source to share