package MooseX::Status::Verby::Action::Make;
use Moose;
extends qw(Verby::Action::Make);
use Carp qw(carp);
use POE;

sub do {
    my ( $self, $c ) = @_;
    my $wd         = $c->workdir;
    my $makefile   = $c->makefile;
    my @targets    = ( ( $c->target || () ), @{ $c->targets || [] } );
    my @extra_args = ( ( $c->extra_arg || () ), @{ $c->extra_args || [] } );
    my $num_jobs   = $self->num_jobs;
    my $silent     = $self->silent;

    $c->is_make_test(1) if "@targets" eq "test";

    my @cli = (
        $self->make_path,
        "-j$num_jobs",
        ( $silent ? "-s" : () ),
        ( defined($makefile) ? ( "-f" => $makefile ) : () ),
        "-C" => $wd,
        @targets,
        @extra_args,
    );

    $self->create_poe_session(
        c   => $c,
        cli => \@cli,
    );
}

sub finished {
    my ( $self, $c ) = @_;

    my $out = $c->stdout;
    chomp($out);
    my $err = $c->stderr;
    chomp($err);
    my $file = $c->report;

    print $file "# @{ $c->command_line } \n";
    print $file $out;
    print $file $err;

    #    $c->logger->info("test stderr:\n$out") if $c->is_make_test;
    $self->confirm($c);
    $c->program_finished;
}

no Moose;
1;
