#!/usr/bin/perl

# Julian K Field <mailscanner@ecs.soton.ac.uk> 12th April 2009.
# All copyright is that of the author, given above.
# It may only be distributed as part of MailScanner, without prior
# written consent of the author, given above.

# Look for the first path containing site and vendor and put them on the
# front of @INC by using the shell environment variable $PERL5LIB.
# Allow for multiple different locations of the vendor and site paths as
# they may have 32-bit and 64-bit versions, and local and non-local versions
# as well.

use strict;

my($path,@path,%path);
foreach $path (@INC) {
  if ($path =~ /vendor/i) {
    $path =~ s/([^0-9a-z_-]vendor[0-9a-z_-]*)[^0-9a-z_-].*$/$1/i;
    if (!$path{$path}) {
      $path{$path} = 1;
      push @path, $path;
    }
  }
  if ($path =~ /site/i) {
    $path =~ s/([^0-9a-z_-]site[0-9a-z_-]*)[^0-9a-z_-].*$/$1/i;
    if (!$path{$path}) {
      $path{$path} = 1;
      push @path, $path;
    }
  }
}

print join(':', @path);

