[Bast-commits] r3738 - local-lib/1.000/trunk/lib/local

apeiron at dev.catalyst.perl.org apeiron at dev.catalyst.perl.org
Fri Sep 14 01:12:00 GMT 2007


Author: apeiron
Date: 2007-09-14 01:12:00 +0100 (Fri, 14 Sep 2007)
New Revision: 3738

Modified:
   local-lib/1.000/trunk/lib/local/lib.pm
Log:
o   Add a =head1 DESCRIPTION. This fixes installation using FreeBSD's BSDPAN
    extension. Oh. And it also does this neat little thing called telling people
    what the code does. Might be handy.
o   Add rudimentary support with C style shells. Defaults to sh if your
    $ENV{SHELL} isn't defined for some reason (you evil person). Anything that
    doesn't match /csh/ is assumed to be Bourne. If someone makes another
    Futurama-themed shell that isn't Bourne-style, this'll probably spit out
    commands which make that shell break.
o   And add some docs in support of the aforementioned support for csh.


Modified: local-lib/1.000/trunk/lib/local/lib.pm
===================================================================
--- local-lib/1.000/trunk/lib/local/lib.pm	2007-09-13 22:28:41 UTC (rev 3737)
+++ local-lib/1.000/trunk/lib/local/lib.pm	2007-09-14 00:12:00 UTC (rev 3738)
@@ -191,7 +191,23 @@
   while (@envs) {
     my ($name, $value) = (shift(@envs), shift(@envs));
     $value =~ s/(\\")/\\$1/g;
-    $out .= qq{export ${name}="${value}"\n};
+
+    # rather basic csh detection, goes on the assumption that something won't
+    # call itself csh unless it really is. also, default to bourne in the
+    # pathological situation where a user doesn't have $ENV{SHELL} defined.
+    # note also that shells with funny names, like zoid, are assumed to be
+    # bourne.
+    my $shellbin = 'sh';
+    if(defined $ENV{'SHELL'}) {
+      my @shell_bin_path_parts = File::Spec->splitpath($ENV{'SHELL'});
+      $shellbin = $shell_bin_path_parts[-1];
+    }
+    if($shellbin =~ /csh/) {
+      $out .= qq{setenv ${name} "${value}"\n};
+    }
+    else {
+      $out .= qq{export ${name}="${value}"\n};
+    }
   }
   print $out;
 }
@@ -258,13 +274,29 @@
   $ perl Makefile.PL --bootstrap
   $ make test && make install
   $ echo 'eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)' >>~/.bashrc
+  # Or for C shells...
+  $ /bin/csh
+  % echo $SHELL
+  /bin/csh
+  % perl -I$HOME/perl5/lib/perl5 -Mlocal::lib >> ~/.cshrc
 
 You can also pass --boostrap=~/foo to get a different location (adjust the
-bashrc line appropriately)
+bashrc / cshrc line appropriately)
 
+=head1 DESCRIPTION
+
+This module provides a quick, convenient way of bootstrapping a user-local Perl
+module library located within the user's home directory. It also constructs and
+prints out for the user the list of environment variables using the syntax
+appropriate for the user's current shell (as specified by the C<SHELL>
+environment variable), suitable for directly adding to one's shell configuration
+file.
+
 =head1 LIMITATIONS
 
-No support for non-bourne shells.
+Rather basic shell detection. Right now anything with csh in its name is
+assumed to be a C shell or something compatible, and everything else is assumed
+to be Bourne.
 
 Bootstrap is a hack and will use CPAN.pm for ExtUtils::MakeMaker even if you
 have CPANPLUS installed.
@@ -275,6 +307,17 @@
 
 Patches very much welcome for any of the above.
 
+=head1 ENVIRONMENT
+
+=over 4
+
+=item SHELL
+
+local::lib looks at the user's C<SHELL> environment variable when printing out
+commands to add to the shell configuration file.
+
+=back
+
 =head1 AUTHOR
 
 Matt S Trout <mst at shadowcat.co.uk> http://www.shadowcat.co.uk/




More information about the Bast-commits mailing list