#!/usr/bin/perl

use strict;
use warnings;

use File::Find;

my $target = 'dategrep';

open( my $standalone, '>', $target) or die "Can't open target: $!\n";

sub wanted {
    return unless -f;
    open( my $fh, '<', $_ )
      or die "Can't open $_: $!\n";
    while (<$fh>) {
        next if /^use App::dategrep/;
        next if /^eval "require/;
        s/^use parent 'App/use parent -norequire, 'App/g;
        next if /^=pod/ ... /^=cut/;
        print {$standalone} $_;
    }
}

my $script = 'script/dategrep';

open( my $fh, '<', $script ) or die "Can't open $script: $!\n";

while (<$fh>) {
    next if /^use App::dategrep/;
    print {$standalone} $_;
}

finddepth( \&wanted, 'lib' );

chmod 0755, $target;

exit 0;
