<commit_before>package NQP::Config;
use strict;
use warnings;

use base qw(Exporter);
our @EXPORT_OK = qw(cmp_rev read_parrot_config slurp system_or_die);

sub parse_revision {
    my $rev = shift;
    my $sep = qr/[_.]/;
    $rev =~ /(\d+)$sep(\d+)(?:$sep(\d+))?(?:-(\d+)-g[a-f0-9]*)?$/
        or die "Unrecognized revision specifier '$rev'\n";
    return ($1, $2, $3 || 0, $4 || 0);
}


sub cmp_rev {
    my ($a, $b) = @_;
    my @a = parse_revision($a);
    my @b = parse_revision($b);
    my $cmp = 0;
    for (0..3) {
        $cmp = $a[$_] <=> $b[$_];
        last if $cmp;
    }
    $cmp;
}


sub read_parrot_config {
    my @parrot_config_src = @_;
    my %config = ();
    for my $file (@parrot_config_src) {
        no warnings;
        if (-x $file && open my $PARROT_CONFIG, '-|', "$file --dump") {
            print "\nReading configuration information from $file ...\n";
            while (<$PARROT_CONFIG>) {
                if (/(\w+) => '(.*)'/) { $config{"parrot::$1"} = $2 }
            }
            close($PARROT_CONFIG) or die $!;
        }
        elsif (-r $file && open my $PARROT_CONFIG, '<', $file) {
            print "\nReading configuration information from $file ...\n";
            while (<$PARROT_CONFIG>) {
                if (/P0\["(.*?)"\], "(.*?)"/) { $config{"parrot::$1"} = $2 }
            }
            close($PARROT_CONFIG) or die $!;
        }
        last if %config;
    }
    return %config;
}
<commit_msg>Allow using parrot_config found in search path.  cotto++<commit_after>package NQP::Config;
use strict;
use warnings;

use base qw(Exporter);
our @EXPORT_OK = qw(cmp_rev read_parrot_config slurp system_or_die);

sub parse_revision {
    my $rev = shift;
    my $sep = qr/[_.]/;
    $rev =~ /(\d+)$sep(\d+)(?:$sep(\d+))?(?:-(\d+)-g[a-f0-9]*)?$/
        or die "Unrecognized revision specifier '$rev'\n";
    return ($1, $2, $3 || 0, $4 || 0);
}


sub cmp_rev {
    my ($a, $b) = @_;
    my @a = parse_revision($a);
    my @b = parse_revision($b);
    my $cmp = 0;
    for (0..3) {
        $cmp = $a[$_] <=> $b[$_];
        last if $cmp;
    }
    $cmp;
}


sub read_parrot_config {
    my @parrot_config_src = @_;
    my %config = ();
    for my $file (@parrot_config_src) {
        no warnings;
        if (open my $PARROT_CONFIG, '-|', "$file --dump") {
            print "\nReading configuration information from $file ...\n";
            while (<$PARROT_CONFIG>) {
                if (/(\w+) => '(.*)'/) { $config{"parrot::$1"} = $2 }
            }
            close($PARROT_CONFIG) or die $!;
        }
        elsif (-r $file && open my $PARROT_CONFIG, '<', $file) {
            print "\nReading configuration information from $file ...\n";
            while (<$PARROT_CONFIG>) {
                if (/P0\["(.*?)"\], "(.*?)"/) { $config{"parrot::$1"} = $2 }
            }
            close($PARROT_CONFIG) or die $!;
        }
        last if %config;
    }
    return %config;
}

{'fraction_non_alphanumeric': 0.20681431005110731, 'fraction_numerical': 0.01090289608177172, 'mean_word_length': 2.002044989775051, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6683895', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1080, 'n_words': 255}