How to share ENV variables among Perl scripts

I have two Perl scripts along with a GIT hook script. There I check the GIT workflow. Here are the scripts that invoke the stack.

pre-push -> unpush-changes -> dependency tree

There is a for loop in unpush-changes perl script that will call the perl script dependency tree.

pre push

system("unpushed-changes");
  my $errorMsg = $ENV{'GIT_FLOW_ERROR_MSG'}// '';
  if($errorMsg eq "true"){
     print "Error occured!";
   }

unpush-changes.pl

  for my $i (0 .. $#uniqueEffectedProjectsList) {
      my $errorMsg = $ENV{'GIT_FLOW_ERROR_MSG'}// '';
      if($errorMsg ne "true"){
        my $r=system("dependency-tree $uniqueEffectedProjectsList[$i]");
     }else{
        exit 1;
     }

   }

dependency-tree.pl

if(system("mvn clean compile  -DskipTests")==0){
     print "successfully build"; 
     return 1;
 }else{
      $ENV{'GIT_FLOW_ERROR_MSG'} = 'true';
      print "Error occured";
      return 0;
  }

script, , ENV unpush- script. ENV - , true. , , , , . , . , , .

+4
2

, , , . Env::Modify , "shell magic" , perlfaq.

:

use Env::Modify 'system',':bash';

print $ENV{FOO};                   #   ""
system("export FOO=bar");
print $ENV{FOO};                   #   "bar"
...
print $ENV{GIT_FLOW_ERROR_MSG};    #   ""
system("unpushed-changes");
print $ENV{GIT_FLOW_ERROR_MSG};    #   "true"
...
+8

@mob, . Env::Modify perl lib. lib Env::Modify. script Env::Modify, .

Utils.pm unpush-changes dependency-tree, /c/lib/My/Utils.pm.

Utils.pm

package My::Utils;
use strict;
use warnings;

use Exporter qw(import); 
our @EXPORT_OK = qw(build deploy);

sub build {
 system("mvn clean compile  -DskipTests")
 //Do  other things
}

sub deploy {
 //Do  things
}

1;

pre-push.

#!/usr/bin/perl
use strict;
use warnings;
use File::Basename qw(dirname);
use Cwd  qw(abs_path);
use lib dirname(dirname abs_path $0) . '/lib'; 
use My::Utils qw(build deploy); // or use lib '/c/lib';

build();
deploy();

ENV.

+1

Source: https://habr.com/ru/post/1679975/


All Articles