#!/usr/bin/env perl
use strict;
use Module::ScanDeps;
use File::Copy;
use File::Spec;
use File::Path;

my $SCANFILE = shift;
my $DEST = shift;

sub copy_file {
    my $fh = shift;
    my $src = $$fh{'file'};
    my $dest = File::Spec->join( $DEST, $$fh{'store_as'} );
    my ($volume, $directories, $file) = File::Spec->splitpath( $dest );
    my $destdir = File::Spec->catpath( $volume, $directories, "" );
    mkpath( $destdir );
    copy( $src, $dest );
}

my $scan = Module::ScanDeps->new;
$scan->set_file( $SCANFILE );
$scan->calculate_info;
my $files = $scan->get_files;
while ( my ($key, $value) = each(%$files) ) {
    if ( $key eq "main" ) {
        copy_file( $value );
    } else {
        for my $item (@$value) {
            copy_file( $item );
        }
    }
}
