The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/env perl

use strict;
use warnings;
use autodie qw( :all );

use 5.01000;

use File::Copy qw( copy );
use File::Find::Rule;
use File::pushd;
use File::Temp qw( tempdir );
use Path::Class qw( file );

my $branch = shift || 'master';

my $tempdir = tempdir( CLEANUP => 1 );

{
    my $dir = pushd($tempdir);

    system(
        'git',      'clone',
        '--branch', $branch,
        'git://github.com/maxmind/MaxMind-DB-Reader-perl.git',
        'pp'
    );
}

my $t_root = "$tempdir/pp/t";

for my $file ( File::Find::Rule->name(qr/\.t$/)->in($t_root) ) {
    open my $fh, '<', $file;
    my $first_line = <$fh>;

    next if $first_line =~ /^\# PP only/;

    my $to_file = file( 't', $file =~ s{^\Q$t_root\E/}{}r );

    $to_file->dir()->mkpath( 0, 0755 );
    copy( $file => $to_file );
}