#!/usr/bin/env perl

use 5.24.0;

use strict;
use warnings;
use lib './lib';

use Module;
use Dist;
use Storable qw/retrieve/;
use Data::Dumper;

my $data = retrieve 'everything.stor';

my @failed_list = grep {my $s=$data->{jobstatus}{$_}{status}; $s ne 'success' && $s ne 'inc failed'} grep {defined $_ && $_ ne ''} keys($data->{jobstatus}->%*);

my %mods;

$|++;

LOOP: for my $mod ($data->{modules}->@*) {
  my $status = $data->{jobstatus}{$mod}{status} // "";

  if ($status ne 'success' && $status ne 'inc failed') {
    print STDERR "DEP Checking $mod\n";
    my $module = Module->new_module($mod);
    my @dependedonby = $module->get_failed_descendants(\@failed_list);

    $mods{$mod} = 0+@dependedonby;
    printf "%05d %s\n", $mods{$mod}, $mod;
  }
}
