package Simba::Build;
use strict;
use warnings;

use Module::Build;
use Data::Dumper;

our @ISA = ('Module::Build');

sub ACTION_install {
    my $self = shift;
    # print STDERR Dumper($self), "\n";
    # print STDERR $self->install_path->{lib}, "\n";
    # print STDERR Dumper($self->install_map), "\n";
    my $lib = $self->install_map->{'blib/lib'};
    for my $script (glob('blib/script/*')) {
	open (my $in, '<', $script) or die "cannot open $script: $!";
	open (my $out, '>', "$script.$$") or die "cannot open $script.$$: $!";
	while (<$in>) {
	    if (m{^use lib 'blib/lib'}) {
		print $out "use lib '$lib';\n";
	    } else {
		print $out $_ or die "cannot write to $script.$$: $!";
	    }
	}
	close $in or die "cannot close $script: $!";
	close $out or die "cannot close $script.$$: $!";
	rename "$script.$$", $script or die "cannot rename $script.$$ to $script: $!";
	chmod(0555, $script);
    }
    $self->SUPER::ACTION_install;
}


