The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
require 5.008;

# do we have threads or forks??
my $module;
BEGIN {
    $module=  "Thread::Queue::Any";

    require Config;
    Config->import;

    if ( !$Config{useithreads} ) {

        eval { require forks };
        if ($@) {
            print <<"TEXT";
$module requires a version of perl that has threads enabled or
which has the forks.pm module installed.
TEXT
            exit 0;
        }
    }
} #BEGIN

# set up stuff
use ExtUtils::MakeMaker;
use File::Copy qw( mv );

# set version and dependency info
eval "use Devel::Required";

# initializations
my $lib_tree= 'Thread/Queue';
my @postfix=  qw( blead maint );
my $maint=    ( $] < 5.014 ) || 0;

# do we have an override?
if (@ARGV) {
    my ($type)= @ARGV;
    if ( $type eq 'maint' ) {
        $maint= 1;
    }

    elsif ( $type eq 'blead' ) {
        $maint= 0;
    }

    else {
        die "Don't understand '$type' to force version to test / install";
    }

    print STDERR "Forcing to use the '$type' version of the code\n";
}

# create shortcuts
my $this= $postfix[$maint];
my $that= $postfix[ !$maint ];

# make sure empty directories exist, 'make dist' doesn't include them
mkdir 'lib_blead';
mkdir 'lib_blead/Thread';
mkdir 'lib_blead/Thread/Queue';
mkdir 't_blead';

# need to move files into place
if ( my @files= glob( "lib_$this/$lib_tree/*" ) ) {
    print STDERR "Moving $this files into position\n";

    # move current files away
    mv "lib/$lib_tree/$_", "lib_$that/$lib_tree/${_}_$that"
      foreach
        map { m#/([^/\.]+\.pm)$# }
        glob( "lib/$lib_tree/*" );
    mv "t/$_", "t_$that/${_}_$that"
      foreach
        map { m#/([^/\.]+\.t)$# }
        glob( "t/*" );

    # put files into place
    mv "lib_$this/$lib_tree/${_}_$this", "lib/$lib_tree/$_"
      foreach
        map { m#/([^/\.]+\.pm)_$this$# }
        @files;
    mv "t_$this/${_}_$this", "t/$_"
      foreach
        map { m#/([^/]+\.t)_$this$# }
        glob( "t_$this/*" );

    # make sure we will copy to blib
    unlink "blib/lib/$lib_tree/Any.pm";
}

# right files already there
else {
    print STDERR "Files for $this already in position\n";
}

# set up prerequisites
my @prereq_pm= (
  'Thread::Queue' => 0,
);
push @prereq_pm, (
  'Test::More'    => 0.88,
) if !$maint;

# set up
WriteMakefile (
 NAME         => $module,
 AUTHOR       => 'Elizabeth Mattijsen (liz@dijkmat.nl)',
 ABSTRACT     => 'thread-safe queues for any data-structure',
 VERSION_FROM => 'lib/Thread/Queue/Any.pm',
 LICENSE      => 'perl',
 PREREQ_PM    => { @prereq_pm },
);