#!/usr/bin/env perl

use strict;
use warnings;
use FFI::Temp;
use File::Glob qw( bsd_glob );

my $module = shift @ARGV;

my $skip;

unless($] > 5.010)
{
  $skip = "ZMQ::FFI requires Perl 5.10" if $module eq 'ZMQ::FFI';
}

if($skip)
{
  print $skip, "\n";
  exit;
}

my $build_root = bsd_glob( "~/test-build-root-tmp");
mkdir $build_root unless -d $build_root;

my $lib = FFI::Temp->newdir;

my @cmd = ( 'cpanm', '-n', '-l' => $lib, '--installdeps', $module );

print "+@cmd\n";
system @cmd;
exit 2 if $?;


@cmd = ( 'cpanm', '-l' => $lib, '-v', '--reinstall', $module );
print "+@cmd\n";
system @cmd;

if($?)
{
  system 'tail', -f => '/home/travis/.cpanm/build.log';
  exit 2
}