remove $interpolate option from docs of build_environment_vars_for
[p5sagit/local-lib.git] / lib / local / lib.pm
index 8718f78..41a51d6 100644 (file)
@@ -15,6 +15,7 @@ sub import {
   my ($class, @args) = @_;
 
   my @steps;
+  my %opts;
 
   while (@args) {
     my $arg = shift @args;
@@ -33,13 +34,20 @@ DEATH
     elsif ($arg eq '--self-contained') {
       die "FATAL: The local::lib --self-contained flag has never worked reliably and the original author, Mark Stosberg, was unable or unwilling to maintain it. As such, this flag has been removed from the local::lib codebase in order to prevent misunderstandings and potentially broken builds. The local::lib authors recommend that you look at the lib::core::only module shipped with this distribution in order to create a more robust environment that is equivalent to what --self-contained provided (although quite possibly not what you originally thought it provided due to the poor quality of the documentation, for which we apologise).\n";
     }
-    elsif( $arg eq '--deactivate' ) {
-      my $path = shift @args;
+    elsif( $arg =~ /^--deactivate(?:=(.*))?$/ ) {
+      my $path = defined $1 ? $1 : shift @args;
       push @steps, ['deactivate', $path];
     }
     elsif ( $arg eq '--deactivate-all' ) {
       push @steps, ['deactivate_all'];
     }
+    elsif ( $arg =~ /^--shelltype(?:=(.*))?$/ ) {
+      my $shell = defined $1 ? $1 : shift @args;
+      $opts{shelltype} = $shell;
+    }
+    elsif ( $arg eq '--no-create' ) {
+      $opts{no_create} = 1;
+    }
     elsif ( $arg =~ /^--/ ) {
       die "Unknown import argument: $arg";
     }
@@ -51,7 +59,7 @@ DEATH
     push @steps, ['activate', undef];
   }
 
-  my $self = $class->new;
+  my $self = $class->new(%opts);
 
   for (@steps) {
     my ($method, @args) = @$_;
@@ -83,6 +91,7 @@ sub bins { $_[0]->{bins}   ||= [ \'PATH' ] }
 sub roots { $_[0]->{roots} ||= [ \'PERL_LOCAL_LIB_ROOT' ] }
 sub extra { $_[0]->{extra} ||= {} }
 sub shelltype { $_[0]->{shelltype} ||= $_[0]->guess_shelltype }
+sub no_create { $_[0]->{no_create} }
 
 my $_archname = $Config{archname};
 my $_version  = $Config{version};
@@ -215,7 +224,8 @@ sub activate {
   my ($self, $path) = @_;
   $self = $self->new unless ref $self;
   $path = $self->resolve_path($path);
-  $self->ensure_dir_structure_for($path);
+  $self->ensure_dir_structure_for($path)
+    unless $self->no_create;
 
   my @active_lls = $self->active_paths;
 
@@ -236,9 +246,11 @@ sub activate {
 }
 
 sub _legacy {
-  my ($self, $path, $deactivating) = @_;
+  my ($self, $path) = @_;
   $self = $self->new unless ref $self;
-  $self = $self->${\($deactivating ? 'deactivate' : 'activate')}($path) if defined $path;
+  if (defined $path) {
+    $self = $self->activate($path);
+  }
   $self;
 }
 
@@ -298,6 +310,10 @@ sub environment_vars_string_for {
         && ${$value->[0]} eq $name) {
       next;
     }
+    if (!ref $value
+        && $value eq $ENV{$name}) {
+      next;
+    }
     $out .= $self->$build_method($name, $value);
   }
   return $out;
@@ -327,9 +343,19 @@ sub build_cmd_env_declaration {
   my $value = $class->_interpolate($args, '%', '%');
   $value =~ s/"/\\"/g
     if defined $value;
-  return defined($value) ? qq{set ${name} "${value}"\n} : qq{set ${name}=\n};
+  return qq{set $name=} . (defined($value) ? qq{"$value"} : '') . "\n";
+}
+sub build_powershell_env_declaration {
+  my ($class, $name, $args) = @_;
+  my $value = $class->_interpolate($args, '$env:');
+  if (defined $value) {
+    $value =~ s/"/\\"/g;
+    return qq{\$env:$name = "$value"\n};
+  }
+  return "Remove-Item Env:\\$name\n";
 }
 
+
 sub _interpolate {
   my ($class, $args, $start, $end) = @_;
   return
@@ -775,6 +801,17 @@ was added by C<local::lib>, instead of adding it.
 Remove all directories that were added to search paths by C<local::lib> from the
 search paths.
 
+=head2 --shelltype
+
+Specify the shell type to use for output.  By default, the shell will be
+detected based on the environment.  Should be one of: C<bourne>, C<csh>,
+C<cmd>, or C<powershell>.
+
+=head2 --no-create
+
+Prevents C<local::lib> from creating directories when activating dirs.  This is
+likely to cause issues on Win32 systems.
+
 =head1 METHODS
 
 =head2 ensure_dir_structure_for
@@ -807,7 +844,7 @@ given path as the base directory.
 
 =over 4
 
-=item Arguments: $path, $interpolate
+=item Arguments: $path
 
 =item Return value: %environment_vars