#!/usr/bin/perl
use warnings;
use strict;

use autodie;
use File::Find;
use File::Slurp;
use Data::Dump qw(dump);

sub print_job {
	return unless @_;
	print "JOB ",dump(@_),$/;
}

find(sub {
	my $name = $_;
	return if ! m/\.pm$/;
	open(my $fh, '<', $name);
	my $job;
	while(<$fh>) {
		chomp;
		if (/sub\s+(\w+)\s*:\s*Job/) {
			print_job $name => $job;
			$job = { name => $1 };
		} elsif ( m/\$(\w+)->add_task\(\s*'(\w+)'/ ) {
			push @{ $job->{task}->{$1} }, $2;
		} elsif ( m/\$(\w+)->wait/ ) {
			if ( exists $job->{task}->{$1} ) {
				push @{ $job->{task}->{$1} }, 'wait';
			}
		} elsif ( m/\$self->(do\w*)\(\s*'(\w+)'/ ) {
			push @{ $job->{$1} }, $2;
		}
	}
	print_job $name => $job;
}, 'lib');
