I have two Perl scripts along with GIT hook script.In there i am validating the GIT work flow.Here is the scripts calling stack.
pre-push -> unpush-changes
As @mob mentioned there are two ways to achieve this.Env::Modify or as a perl lib.So i have chosen lib over Env::Modify.because i want to run this script in every machine either explicitly Env::Modify package is installed or not.
I have written Utils.pm bundling both unpush-changes and dependency-tree functionalities and i saved it under /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;
Then i used previously created library in my pre-push hook.
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();
No longer needs to worry about the ENV variables.Reference
In general, child processes inherit a separate copy of the environment from their parent and changes made by the child do not propagate to the parent's environment. Env::Modify offers a workaround for this issue implementing the "shell magic" that the perlfaq talks about.
Typical usage:
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"
...