App-Env

 view release on metacpan or  search on metacpan

lib/App/Env/Example.pm  view on Meta::CPAN

or, if there is a site specific version:

  App::Env::<SITE>::<application>

It is very important that the loaded environment be based upon the
I<current> environment.  For example, if the environment is derived
from running a shell script, make sure either that the shell script is
run without running the user's startup file, or that any differences
between the current environment and that constructed by the script
which are not due to the application are resolved in the current
environment's favor.  For example, say that B<LD_LIBRARY_PATH> is set
in the user's F<.cshrc> file:

  setenv LD_LIBRARY_PATH /my/path1

and that before invoking B<App::Env> the user has modified it to

  /my/path1:/my/path2

If a B<csh> script is sourced to create the environment, and B<csh> is
not run with the B<-f> flag, the user's F<.cshrc> will be sourced, the

script/appexec  view on Meta::CPAN

    bash => 'bash',
    tcsh => 'tc',
    sh   => 'bourne',
    csh  => 'c',
);

# program options; see parse_args();
my %opt;

eval { main() } // do {
    say STDERR "# $prog: $_" foreach split /\n/, $@;    ## no critic(InputOutput::RequireCheckedSyscalls)
    exit 1;
};

exit 0;

sub main {
    parse_args();

    help( 1 ) if $opt{help};
    help( 2 ) if $opt{usage};

script/appexec  view on Meta::CPAN

            ( map { [ $_ => { AppOpts => $appopts{$_} } ] } @envs ),
            { ( defined $opt{site} ? ( Site => $opt{site} ) : () ), } );
    } // die( "error setting up environment `$opt{env}': $@\n" );

    $env->setenv( $_ ) for @{ $opt{delete} };
    $env->setenv( $_, $opt{define}{$_} ) for keys %{ $opt{define} };

    dumpenv( $env, $opt{dumpenv}, $opt{dumpvar} ) if $opt{dumpenv};

    if ( @ARGV ) {
        say join( q{ }, @ARGV )    ## no critic(InputOutput::RequireCheckedSyscalls)
          if $opt{verbose};

        %ENV = %$env;              ## no critic( Variables::RequireLocalizedPunctuationVars )

        die( "$ARGV[0] does not exist, is not executable, or is not in PATH\n" )
          unless ( file_name_is_absolute( $ARGV[0] ) && -e $ARGV[0] )
          || defined which( $ARGV[0] );

        exec { $ARGV[0] } @ARGV
          or die( "can't exec $ARGV[0]: not in path?\n" );

script/appexec  view on Meta::CPAN

}

sub dumpenv {
    my ( $env, $fmt, $vars ) = @_;

    $vars = [ keys %$env ] unless @$vars;

    ## no critic (InputOutput::RequireCheckedSyscalls)
    ## no critic (ControlStructures::ProhibitCascadingIfElse)
    if ( $fmt eq 'raw' ) {
        say "$_=",
          (
            length $env->{$_}
            ? App::Env::_Util::shell_escape( $env->{$_} )
            : q{}
          ) for @$vars;
    }

    elsif ( $fmt eq 'unquoted' ) {
        say "$_=$env->{$_}" for @$vars;
    }

    elsif ( $fmt eq 'values' ) {
        say $env->{$_} for @$vars;
    }

    elsif ( $fmt eq 'json' ) {
        require JSON::PP;
        say JSON::PP::encode_json( { map { $_ => $env->{$_} } @$vars } );
    }

    elsif ( $fmt eq 'delta-json' ) {
        my ( $delete, $add ) = delta( $env );
        require JSON::PP;
        say JSON::PP::encode_json( {
            delete => $delete,
            add    => { map { $_ => $env->{$_} } @$add },
        } );
    }

    elsif ( $fmt eq 'delta-args' ) {
        my ( $delete, $add ) = delta( $env );
        say join q{ }, ( map { "-X $_" } @$delete ),
          ( map { "-D $_=" . App::Env::_Util::shell_escape( $env->{$_} ) } @$add );
    }

    else {
        require Shell::Guess;

        if ( $fmt eq 'auto' ) {
            $fmt = Shell::Guess->running_shell;
        }
        else {



( run in 1.528 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )