ShellScript-Env

 view release on metacpan or  search on metacpan

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

}
  


##################
# functions to generate shell scripts, these are considered public
# too.  Are there other common shells that arn't compatible with C or
# Bourne Shell?

# output Bourne Shell.
sub sh {
  my $self = shift;

  my $output = '';
  my $export = 'export ';

  for (sort @{$self->{'order'}}) {
    $export .= "$_ ";

    if ($self->{'utok'}->{$_}) {
      $output .= "$_=`utok ";
    } else {
      $output .= "$_=";
    }


    for (@{$self->{'env'}->{$_}}) {
      $output .= "$_:";
    }
    
    if ($self->{'utok'}->{$_}) {
      $output =~ s/:$/\`\n/;
    } else {
      $output =~ s/:$/\n/;
    }

  }

  if ($export ne 'export ') {
      $output .= $export;
  }
  $output =~ s/\ $/\n/;

  return $output;
}

# output C Shell.
sub csh {
  my $self = shift;

  my $output = '';
  for (@{$self->{'order'}}) {

    my $delimiter = ':';
    # I hate how C Shell set every variable one way, and PATH another.
    # It bugs me to no end.
    if ($_ eq 'PATH') {
      $delimiter = ' ';
      $output .= "set path = (";
    } else {
      $output .= "setenv $_ ";
    }

    if ($self->{'utok'}->{$_}) {
      if ($delimiter ne ':') {
	$output .= "`utok -s '$delimiter' ";
      } else {
	$output .= '`utok ';
      }
    }

    my $item;
    foreach $item (@{$self->{'env'}->{$_}}) {
      if (($_ eq 'PATH') && ($item eq '$PATH')) {
	$output .= "\$path$delimiter";
      } else {
	$output .= "$item$delimiter";
      }
    }

    $delimiter = quotemeta($delimiter);
    if ($self->{'utok'}->{$_}) {
      $output =~ s/$delimiter$/\`\n/;
    } else {
      $output =~ s/$delimiter$/\n/;
    }

    if ($_ eq 'PATH') {
      $output =~ s/\n$/\)\n/;
    }
  }

  return $output;
}


#####################
# Private functions.

# I really wish File::Find's find returned an array.  I also wish it
# worked while tainted.  oh well.
sub dir_find {
  my $self = shift;

  @ShellScript::Env::find = @_;
  undef @ShellScript::Env::found;
  @ShellScript::Env::skip = @{$self->{'skip_dirs'}};

  my @output;
  if (-l $self->{'prefix'}) {


    my $newdir = $self->{'prefix'};
    $newdir =~ s<[^/]*$><>;
    chdir($newdir);

    my $prefix = readlink($self->{'prefix'});
    find(\&wanted, $prefix);
    $prefix = quotemeta($prefix);
    @output = map(s/^$prefix/$self->{'prefix'}/g && $_,
		  @ShellScript::Env::found);



( run in 1.166 second using v1.01-cache-2.11-cpan-97f6503c9c8 )