App-Env

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

      eval's will actually work

0.12  2008-07-11T13:31:09-0400

    * appenv's dumpenv has more output formats. its value is now required.
      previously it was optional, which led to its grabbing
      the environment name if --env wasn't used. bad form.

0.11  2008-06-16T12:27:20-0400

    * new setenv() method allows changing an environment.

0.10  2008-06-15T23:26:29-0400

    * new SysFatal option which will cause system/qexec/capture object
      methods to throw an exception on error.  Uses
      IPC::System::Simple in this case.

    * Default option values may now be changed.

 0.09  2008-03-22T22:44:32-0400

MANIFEST  view on Meta::CPAN

t/lib/App/Env/Site.pm
t/lib/App/Env/Site1/App1.pm
t/lib/App/Env/Site1/App2.pm
t/lib/App/Env/Site1/App3.pm
t/lib/App/Env/Site1/App4.pm
t/lib/App/Env/Site2/App1.pm
t/null.t
t/regressions/capture_tiny.t
t/regressions/disappearing_site.t
t/retrieve.t
t/setenv.t
t/site1.t
t/site2.t
t/site3.t
t/system.t
t/temp.t
t/use1.t
t/use2.t
t/use3.t
t/which.t
templates/CONTRIBUTING.md

README.mkdn  view on Meta::CPAN

            $value = $env->env( $variable_name );

            # this is context 3
            $hash = $env->env( [ $variable_name ] );

    Variable names may be excluded from the list by passing a hash with
    the key `Exclude` as the last argument (valid only in contexts 0 and
    3).  The value is either a scalar or an arrayref composed of match
    specifications (as an arrayref) as described in context 3.

- setenv

        # set an environmental variable
        $env->setenv( $var, $value );

        # delete an environmetal variable
        $env->setenv( $var );

    If `$value` is present, assign it to the named environmental
    variable.  If it is not present, delete the variable.

    **Note:** If the environment refers to a cached environment, this will
    affect all instances of the environment which share the cache.

- module

        $module = $env->module;

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

    }
    else {
        my %env;
        @env{@vars} = map { exists $env->{$_} ? $env->{$_} : undef } @vars;
        return \%env;
    }
}

#-------------------------------------------------------

sub setenv {
    my $self = shift;
    my $var  = shift;

    defined $var
      or App::Env::_Util::croak( "missing variable name argument\n" );

    if ( @_ ) {
        $self->_envhash->{$var} = $_[0];
    }
    else {

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

L</Context 3>.

=item AllowIllegalVariableNames

Not all variable names may be set with a shell command, but may be
inherited from the parent environment.  This option controls whether
such variables are returned by L</env>.  It defaults to true.

=back

=item setenv

  # set an environmental variable
  $env->setenv( $var, $value );

  # delete an environmetal variable
  $env->setenv( $var );

If C<$value> is present, assign it to the named environmental
variable.  If it is not present, delete the variable.

B<Note:> If the environment refers to a cached environment, this will
affect all instances of the environment which share the cache.

=item module

  $module = $env->module;

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


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
user's modifications to B<LD_LIBRARY_PATH> will be lost, and breakage
may happen.

script/appexec  view on Meta::CPAN

    else {
        $appopts{ $envs[0] } = $opt{appopts};
    }

    my $env = eval {
        App::Env->new(
            ( 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" )

t/clone.t  view on Meta::CPAN

#############################################################

my $app1 = App::Env->new( 'App1' );

ok( defined $app1, 'create env' );

# make sure that worked
is( $app1->env( 'Site1_App1' ), 1, 'check env' );

# and brand it
$app1->setenv( 'AppEnvTestID' => $$ );

{

    # now clone it
    my $clone = $app1->clone;

    ok( defined $clone, 'cloned env' );

    is( $clone->env( 'AppEnvTestID' ), $$, 'check cloned env' );

    # change cloned environment
    $clone->setenv( 'CloneTest' => 1 );

    is( $clone->env( 'CloneTest' ), 1, 'check updated cloned env' );

    # and ensure that the parent environment has not been changed

    is( $app1->env( 'CloneTest' ), undef, 'check parent env' );

    # and ensure that the clone has a new object id
    isnt( $app1->lobject_id, $clone->lobject_id, 'clone object id' );

}

# try a cached clone

{
    my $clone = $app1->clone( { Cache => 1 } );
    ok( defined $clone, 'cached cloned env' );

    # and brand it
    $clone->setenv( 'CloneTest' => 2 );

    # and ensure that the parent environment has not been changed
    is( $app1->env( 'CloneTest' ), undef, 'check parent env' );

    # and make sure that the cache id is different
    ok( $clone->cacheid ne $app1->cacheid, 'clone cache id' );

    # and retrieve the cached env
    my $retrieve = App::Env::retrieve( $clone->cacheid );

t/null.t  view on Meta::CPAN


$ENV{NULL_TEST} = 1;

ok( !defined $null1->env( 'NULL_TEST' ), 'null 1: still no env' );

my $null2 = App::Env->new( 'null', { Cache => 0 } );

ok( defined $null2->env( 'NULL_TEST' ) && $null2->env( 'NULL_TEST' ) == 1, 'null 2: env' );


$null2->setenv( NULL_TEST => 3 );

ok( !defined $null1->env( 'NULL_TEST' ), 'null 1: again, still no env' );


done_testing;

t/retrieve.t  view on Meta::CPAN

use App::Env;

my $app1 = App::Env->new( 'App1' );

ok( defined $app1, 'create env' );

# make sure that worked
is( $app1->env( 'Site1_App1' ), 1, "check env" );

# and brand it
$app1->setenv( 'AppEnvTestID' => $$ );

{
    # now retrieve it
    my $app2 = App::Env::retrieve( $app1->cacheid );

    ok( defined $app2, 'retrieve env' );

    is( $app2->env( 'AppEnvTestID' ), $$, "retrieve env" );
}

t/setenv.t  view on Meta::CPAN

#!perl

use Test2::V0;

use Test::Lib;
use App::Env;

my $env = App::Env->new( 'App1' );

$env->setenv( Site1_App1 => 'fooey' );
is( $env->env( 'Site1_App1' ), 'fooey', 'set' );

$env->setenv( 'Site1_App1' );
is( $env->env( 'Site1_App1' ), undef, 'delete' );

done_testing;

t/temp.t  view on Meta::CPAN



my $app1 = App::Env->new( 'App1' );

ok( defined $app1, 'create env' );

# make sure that worked
is( $app1->env( 'Site1_App1' ), 1, 'check env' );

# and brand it
$app1->setenv( 'AppEnvTestID' => $$ );

{
    # now clone a temp of it
    my $app2 = App::Env->new( 'App1', { Temp => 1 } );

    ok( defined $app2, 'temp clone' );

    is( $app2->env( 'AppEnvTestID' ), $$, 'verify parent' );

    # and brand it
    $app2->setenv( 'AppEnvTestID' => -$$ );

    is( $app2->env( 'AppEnvTestID' ), -$$, 'verify clone' );
    is( $app1->env( 'AppEnvTestID' ), $$,  'verify untouched parent' );

    # make sure it hasn't been cached
    ok( !defined App::Env::retrieve( $app2->cacheid ), 'uncached clone' );

}

# check Temp options

xt/author/no-tabs.t  view on Meta::CPAN

    't/lib/App/Env/Site.pm',
    't/lib/App/Env/Site1/App1.pm',
    't/lib/App/Env/Site1/App2.pm',
    't/lib/App/Env/Site1/App3.pm',
    't/lib/App/Env/Site1/App4.pm',
    't/lib/App/Env/Site2/App1.pm',
    't/null.t',
    't/regressions/capture_tiny.t',
    't/regressions/disappearing_site.t',
    't/retrieve.t',
    't/setenv.t',
    't/site1.t',
    't/site2.t',
    't/site3.t',
    't/system.t',
    't/temp.t',
    't/use1.t',
    't/use2.t',
    't/use3.t',
    't/which.t'
);



( run in 0.902 second using v1.01-cache-2.11-cpan-3989ada0592 )