Perl Code

Jerry Benton jerry.benton at mailborder.com
Thu Jan 28 20:29:50 UTC 2016


Can someone better than me at Perl, which isn’t really hard to do, try to make some sense of this? I am thinking this isn’t really applicable since Perl has pretty much been standardized. This is at the beginning of /usr/sbin/MailScanner.

I am think I can cut this down to:

  require MIME::Base64;
  require MIME::QuotedPrint;


---


# Awkard BEGIN block so that we pick up MIME::Base64 from the right place!
BEGIN {
  my(@oldinc, at safecopy,$path, at corepaths, at notcorepaths);

  my $seensv = 0;
  foreach $path (@INC) {
    if ($path =~ /site|vendor/i) {
      $seensv = 1;
    }
    if ($seensv) {
      push @notcorepaths, $path unless $path eq '.';
      next;
    }
    # If it's a simple path before site or vendor, save it for the end
    if ($path =~ m#/usr/(local/)?lib\d*/perl\d*/\d\.\d#) {
      push @corepaths, $path;
    } else {
      push @notcorepaths, $path;
    }
  }

  # Now we have all the site and vendor paths in @notcorepaths, and the
  # perl5 paths in @corepaths. We want notcore + core, so the notcore ones
  # take priority.
  #print STDERR '@INC = ' . "\n" . join("\n", @INC) . "\n";
  @INC = (@notcorepaths, @corepaths);
  #print STDERR '@INC = ' . "\n" . join("\n", @INC) . "\n";

  # Look in /usr/local/mailscanner/utils for the modules
  @oldinc = @INC;
  @safecopy = @INC;

  # Duplicate path with /usr/local/mailscanner/utils stuck on the front
  # of each element
  foreach $path (reverse @oldinc) {
    next unless $path =~ /\//;
    $path =~ s/^\/usr/\/share\/mailscanner\/perl/;
    unshift @INC, $path;
  }

  require MIME::Base64;
  require MIME::QuotedPrint;

  @INC = @safecopy;
}


-
Jerry Benton
www.mailborder.com





More information about the MailScanner mailing list