PDL

 view release on metacpan or  search on metacpan

lib/PDL/AutoLoader.pm  view on Meta::CPAN

}


# Simple 'do' doesn't work with preprocessing -- this replaces
# "do file" and sticks NiceSlice in manually if it's needed (yuck).

sub PDL::AutoLoader::autoloader_do {
  my ($file) = shift;
  if(defined($PDL::NiceSlice::VERSION)) {
    print "AutoLoader: NiceSlice enabled...\n" if($PDL::debug);
    return if !open my $fh ,"<", $file;
    my $text = join "", <$fh>;
    my $script = PDL::NiceSlice::perldlpp("PDL::NiceSlice", $text);
    eval $script;
  } else {
    print "AutoLoader: no NiceSlice...\n" if($PDL::debug);
    do $file;
  }
}


# Expand directories recursively...
sub PDL::AutoLoader::expand_dir {
  my $dir = shift;
  return undef if !-d $dir;
  opendir my($dh), $dir;
  ($dir, map PDL::AutoLoader::expand_dir($_),
    grep +(!m/^\./ && ($_="$dir/$_") && (-d $_)), readdir $dh);
}


=head2 PDL::AutoLoader::expand_path

=for ref 

Expand a compactified path into a dir list

You supply a pathlist and leading '+' and '~' characters get expanded into
full directories.  Normally you don't want to use this -- it's internal to the
autoloader -- but some utilities, like the online documentation searcher, need
to be able to use it.

=cut

sub PDL::AutoLoader::expand_path {
    my @PDLLIB = @_;
    my @PDLLIB_EXPANDED;
    
    print "AutoLoader: Expanding directories from ".join(':',@PDLLIB)."...\n"
	if($PDL::debug);
    local $_;
    foreach $_(@PDLLIB) {
	# Expand ~{name} and ~ conventions.
	if(s/^(\+?)\~(\+||[a-zA-Z0-9]*)//) {
	    if($2 eq '+') {
		# Expand shell '+' to CWD.
		$_= $1 . ($ENV{'PWD'} || '.');
	    } elsif(!$2) {
		# No name mentioned -- use current user.
                #   Ideally would use File::HomeDir->my_home() here
		$_ = $1 . ( $ENV{'HOME'} || (( getpwnam( getlogin || getpwuid($<) ))[7]) )  . $_;
	    } else {
		# Name mentioned - try to get that user's home directory.
		$_ = $1 . ( (getpwnam($2))[7] ) . $_;
	    }
	}
	
	# If there's a leading '+', include all subdirs too.
	push(@PDLLIB_EXPANDED,
	     s/^\+// ? PDL::AutoLoader::expand_dir($_) : $_
	     );
    }

    print "AutoLoader: returning ",join(",",@PDLLIB_EXPANDED),"\n" if($PDL::debug);
    @PDLLIB_EXPANDED;
}


;# Exit with OK status

1;



( run in 0.303 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )