App-Env

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    * no longer uses Object::ID to work around problems with
      Hash::FieldHash and older perls.

0.20  2010-05-28T12:11:51-0400

    * cached environments now keyed off of AppOpts hash
    * (hopefully) improve Windows compatibility

0.15  2008-10-27T14:10:29-0400

    * invert logic of shell magic characters; escape those not known to
      good.

0.14  2008-07-11T21:17:02-0400

    * escape more shell magic characters

0.13  2008-07-11T15:59:30-0400

    * append semi-colons to appenv's dumpenv output so that shell
      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

README.mkdn  view on Meta::CPAN

    This returns the name of the module which was used to load the
    environment.  If multiple modules were used, the names are
    concatenated, separated by the `$;` (subscript separator) character.

- str

        $envstr = $env->str( @match_specifications, \%options );

    This function returns a string which may be used with the \*NIX **env**
    command to set the environment.  The string contains space separated
    `var=value` pairs, with shell magic characters escaped.

    The environment may be pared down by passing _match specifications_
    and an `Exclude` option; see the documentation for the **env** method,
    context 3, for more information.

    Because the **TERMCAP** environment variable is often riddled with
    escape characters, which are not always handled well by shells, the
    **TERMCAP** variable is _always_ excluded unless it is explicitly
    included via an exact variable name match specification. For example,

        $envstr = $env->str( qr/.*/, 'TERMCAP );

    is the only means of getting all of the environment returned.

- system

        $env->system( $command, @args );

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


    push @exclude, 'TERMCAP'
      if List::Util::none { $_ eq 'TERMCAP' } @$include;

    # exclude any variables with non-word characters
    push @exclude, qr/\W/
      unless $opt{AllowIllegalVariableNames};

    my $env  = $self->_envhash;
    my @vars = grep { exists $env->{$_} } $self->_filter_env( $include, \@exclude );
    return join( q{ }, map { "$_=" . App::Env::_Util::shell_escape( $env->{$_} ) } @vars );
}

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

# return a list of included variables, in the requested
# order, based upon a list of include and exclude specs.
# variable names  passed as plain strings are not checked
# for existance in the environment.
sub _filter_env {
    my ( $self, $included, $excluded ) = @_;

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

This returns the name of the module which was used to load the
environment.  If multiple modules were used, the names are
concatenated, separated by the C<$;> (subscript separator) character.

=item str

  $envstr = $env->str( @match_specifications, \%options );

This function returns a string which may be used with the *NIX B<env>
command to set the environment.  The string contains space separated
C<var=value> pairs, with shell magic characters escaped.

The environment may be pared down by passing I<match specifications>
and an C<Exclude> option; see the documentation for the B<env> method,
L</Context 4>, for more information.

Because the B<TERMCAP> environment variable is often riddled with
escape characters, which are not always handled well by shells, the
B<TERMCAP> variable is I<always> excluded unless it is explicitly
included via an exact variable name match specification. For example,

  $envstr = $env->str( qr/.*/, 'TERMCAP );

is the only means of getting all of the environment returned.

B<Note!> By default variables with illegal names (that is,
characters which match B<qr/\W/> are I<not> output).

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


    return () if !defined $site || $site eq q{};
    return $site;

# App::Env::_Util::croak( "Environment variable APP_ENV_SITE is only obeyed at the time that ${ \__PACKAGE__ } is loaded" )
#   if ( defined( APP_ENV_SITE ) xor defined $ENV{APP_ENV_SITE} )
#   || ( defined( APP_ENV_SITE ) && defined $ENV{APP_ENV_SITE} && APP_ENV_SITE ne $ENV{APP_ENV_SITE} );
}


sub shell_escape {
    my $str = shift;

    # empty string
    return q{''} unless length( $str );

    # otherwise, escape all but the "known" non-magic characters.
    $str =~ s{([^\w/.:=\-+%@,])}{\\$1}go;

    return $str;
}

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

sub modulename {
    return join( q{::}, 'App::Env', grep { defined } @_ );
}

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

deleteCacheEntry
exclude_param_check
existsCacheEntry
existsModule
getCacheEntry
is_CacheEmpty
loadModuleList
modulename
require_module
setCacheEntry
shell_escape
uncache

=head1 SUPPORT

=head2 Bugs

Please report any bugs or feature requests to bug-app-env@rt.cpan.org  or through the web interface at: L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-Env>

=head2 Source

script/appexec  view on Meta::CPAN

    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;

script/appexec  view on Meta::CPAN

        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 {
            die( "unknown dump format: $fmt\n" )

script/appexec  view on Meta::CPAN

=item C<csh>

=item C<ksh>

=item C<tcsh>

Output commands to set the environment appropriate to the specified shell.

=item C<raw>

Output C<key=value> where C<value> has shell metacharacters and spaces escaped

=item C<unquoted>

Output C<key=value>.

=item C<values>

Output only the values one per line.  Only eally useful with L<--dumpvar>.

=item C<json>



( run in 0.574 second using v1.01-cache-2.11-cpan-c21f80fb71c )