-Note this is kept seperate from PERL5LIB just in case....
+Note this is kept seperate from PERL5LIB just in case.
+
+As an added bonus, you can use a leading \'+\' on a diectory name to
+search not just that directory but also all its subdirs. The subdirs
+are determined by explicit search, and searches occur at startup and
+again each time you change the number of elements in @PDLLIB.
+
+e.g.
+
+setenv PDLLIB \"+~kgb/PDL\"
+
+will search /home/kgb/PDL and all its subdirectories for .pdl files.
sub AUTOLOAD {
+ my $PDLLIB_CT;
+ my @PDLLIB_EXPANDED;
+
local @INC = @INC;
$AUTOLOAD =~ /::([^:]*)$/;
my $func = $1;
@@ -124,9 +138,33 @@
# Trap spurious calls from \'use UnknownModule\'
goto &$AUTOLOAD if ord($func)==0;
+
+
+ # Check if the PDLLIB needs to be expanded and, if so, expand it.
+ # This only updates when PDLLIB changes size, which should be OK
+ # for most things but doesn\'t catch new directories in expanded
+ # directory trees. It seems like an OK compromise between never
+ # catching anything and always thrashing through the directories.
+ if($PDLLIB_CT != scalar(@PDLLIB)) {
+ print \"Expanding directories from \".join(\',\',@PDLLIB).\"...\\n\"
+ if($PDL::verbose);
+ local $_;
+ $PDLLIB_CT = scalar(@PDLLIB);
+ foreach $_(@PDLLIB) {
+ # Expand ~{name} and ~ conventions
+ s/^(\\+?)\\~([a-zA-Z0-9]*)// &&
+ ($_ = $1.((getpwnam($2 || getlogin))[7]).$_ );
+
+ # If there\'s a leading \'+\', include all subdirs too.
+ push(@PDLLIB_EXPANDED,
+ s/^\\+// ? &PDL::AutoLoader::expand_dir($_) : $_
+ );
+ }
+ }
+
print \"Loading $func.pdl...\\n\" if $PDL::verbose;
- for my $dir (@PDLLIB) {
+ for my $dir (@PDLLIB_EXPANDED) {
my $file = $dir . \"/\" . \"$func.pdl\";
if (-e $file) {
# Autoload
@@ -151,6 +189,28 @@
None
--- PDL-2.003/Basic/AutoLoader.pm Tue Aug 18 14:17:18 1998
+++ PDL-working/Basic/AutoLoader.pm Mon Mar 20 11:56:06 2000
@@ -25,7 +25,18 @@
setenv PDLLIB \"/home/kgb/pdllib:/local/pdllib\"
-Note this is kept seperate from PERL5LIB just in case....
+Note this is kept seperate from PERL5LIB just in case.
+
+As an added bonus, you can use a leading \'+\' on a diectory name to
+search not just that directory but also all its subdirs. The subdirs
+are determined by explicit search, and searches occur at startup and
+again each time you change the number of elements in @PDLLIB.
+
+e.g.
+
+setenv PDLLIB \"+~kgb/PDL\"
+
+will search /home/kgb/PDL and all its subdirectories for .pdl files.
=head2 AUTO-SCANNING
@@ -117,6 +128,9 @@
push @PERLDL::AUTO, \\&PDL::AutoLoader::reloader;
sub AUTOLOAD {
+ my $PDLLIB_CT;
+ my @PDLLIB_EXPANDED;
+
local @INC = @INC;
$AUTOLOAD =~ /::([^:]*)$/;
my $func = $1;
@@ -124,9 +138,33 @@
# Trap spurious calls from \'use UnknownModule\'
goto &$AUTOLOAD if ord($func)==0;
+
+
+ # Check if the PDLLIB needs to be expanded and, if so, expand it.
+ # This only updates when PDLLIB changes size, which should be OK
+ # for most things but doesn\'t catch new directories in expanded
+ # directory trees. It seems like an OK compromise between never
+ # catching anything and always thrashing through the directories.
+ if($PDLLIB_CT != scalar(@PDLLIB)) {
+ print \"Expanding directories from \".join(\',\',@PDLLIB).\"...\\n\"
+ if($PDL::verbose);
+ local $_;
+ $PDLLIB_CT = scalar(@PDLLIB);
+ foreach $_(@PDLLIB) {
+ # Expand ~{name} and ~ conventions
+ s/^(\\+?)\\~([a-zA-Z0-9]*)// &&
+ ($_ = $1.((getpwnam($2 || getlogin))[7]).$_ );
+
+ # If there\'s a leading \'+\', include all subdirs too.
+ push(@PDLLIB_EXPANDED,
+ s/^\\+// ? &PDL::AutoLoader::expand_dir($_) : $_
+ );
+ }
+ }
+
print \"Loading $func.pdl...\\n\" if $PDL::verbose;
- for my $dir (@PDLLIB) {
+ for my $dir (@PDLLIB_EXPANDED) {
my $file = $dir . \"/\" . \"$func.pdl\";
if (-e $file) {
# Autoload
@@ -151,6 +189,28 @@
eval $toeval;
+}
+
+# Expand directories recursively...
+sub PDL::AutoLoader::expand_dir {
+ local $d;
+ local @list;
+ local @subdirs;
+
+ local $dir = shift;
+
+ if(! -d $dir) { return undef; }
+ push(@list,$dir);
+
+ opendir(FOO,$dir);
+
+ @subdirs = grep((!m/^\\./ && ($_=\"$dir/$_\") && (-d $_)), readdir(FOO));
+ closedir FOO;
+
+ while(defined ($d = shift @subdirs)) {
+ push(@list,&PDL::AutoLoader::expand_dir($d));
+ }
+ return @list;
}
;# Exit with OK status
Revised patch to work with 2.004
Revised. DON\'T use Netscape cut-n-paste to get or put patches! It loses backslash characters!