I have a bunch of perl scripts, each of them needs to have an identical BEGIN section, which adds to @INC the path of perl modules we developed. Because it is not a sub, I cannot simply call it. Currently I inlcude this section in every perl script, which is obviously a headache to maintain. Is there a easier way to include the BEGIN section?
BEGIN
{
my $current_script_dir = File::Basename::dirname(File::Spec::Functions::rel2abs($0));
# Assume that the root of all libraries is two levels up from the directory of the
# script being run.
my $all_libs_root = File::Spec->canonpath("$current_script_dir/../..");
# Make sure the path is absolute,
$all_libs_root = File::Spec->rel2abs($all_libs_root);
unshift(@INC, "$all_libs_root");
}