package Module::Install::Pugs;
use Module::Install::Base; @ISA = qw(Module::Install::Base);
use strict;
use Config;

# XXX This doesn't work...
sub WritePugs {
    my $self = shift;
    $self->WriteAll->WriteAll(@_);
    $self->fix_pugs_makefile;
}

sub pugs_fix_makefile {
    my $self = shift;
    my $pugs = "pugs$Config{_exe}";
    my $base = $self->{_top}{base};
    my $full_pugs = "$base/$pugs";
    my $full_t = "$base/t";
    open MAKEFILE, '< Makefile' or die $!;
    my $makefile = do { local $/; <MAKEFILE> };
    $full_pugs =~ s{\\}{\\\\}g; $full_pugs =~ s{'}{\\'}g;
    $full_t =~ s{\\}{\\\\}g; $full_t =~ s{'}{\\'}g;
    $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/ENV->{HARNESS_PERL} = q*$full_pugs*; ENV->{PERL6LIB} = q*$full_t*; $1/;
    $makefile =~ s/("-MExtUtils::Command::MM")/"-Iinc" $1/g;
    close MAKEFILE;
    open MAKEFILE, '> Makefile' or die $!;
    print MAKEFILE $makefile;
    close MAKEFILE;
}

1;
