<commit_before>package Resmon::Config;

use strict;

sub new {
  my $class = shift;
  my $filename = shift;
  my $self = bless {
    configfile => $filename,
    modstatus => '',
    # Defaults
    timeout => 10
  }, $class;
  open(CONF, "<$filename") || return undef;

  my $current;
  my $line = 0;
  while(<CONF>) {
    $line++;
    next if /^\s*#/;
    next if /^\s*$/;
    if($current) {
      if(/^\s*(\S+)\s*:\s*(.+)\s*$/) {
	my %kvs;
	$kvs{'type'} = $current;
        $kvs{'object'} = $1;
	my @params = split(/,/, $2);
	grep { $kvs{$1} = $2 if /^\s*(\S+)\s*=>\s*(\S.+\S)\s*$/ } @params;
        my $object = bless \%kvs, "Resmon::Module::$current";
        push(@{$self->{Module}->{$current}}, $object);

        # Test to make sure the module actually works
        my $coderef;
        eval { $coderef = Resmon::Module::fetch_monitor($current); };
        if (!$coderef) {
            # Try to execute the config_as_hash method. If it fails, then
            # the module didn't load properly (e.g. syntax error).
            eval { $object->config_as_hash; };
            if ($@) {
                # Module failed to load, print error and add to failed
                # modules list.
                print STDERR "Problem loading module $current\n";
                print STDERR "This module will not be available\n";
                $self->{'modstatus'} .= "$current ";
            }
        }

      } elsif (/^\s*\}\s*$/) {<commit_msg>Allow object names with spaces in them<commit_after>package Resmon::Config;

use strict;

sub new {
  my $class = shift;
  my $filename = shift;
  my $self = bless {
    configfile => $filename,
    modstatus => '',
    # Defaults
    timeout => 10
  }, $class;
  open(CONF, "<$filename") || return undef;

  my $current;
  my $line = 0;
  while(<CONF>) {
    $line++;
    next if /^\s*#/;
    next if /^\s*$/;
    if($current) {
      if(/^\s*(\S(?:.*\S)?)\s*:\s*(.+)\s*$/) {
	my %kvs;
	$kvs{'type'} = $current;
        $kvs{'object'} = $1;
	my @params = split(/,/, $2);
	grep { $kvs{$1} = $2 if /^\s*(\S+)\s*=>\s*(\S.+\S)\s*$/ } @params;
        my $object = bless \%kvs, "Resmon::Module::$current";
        push(@{$self->{Module}->{$current}}, $object);

        # Test to make sure the module actually works
        my $coderef;
        eval { $coderef = Resmon::Module::fetch_monitor($current); };
        if (!$coderef) {
            # Try to execute the config_as_hash method. If it fails, then
            # the module didn't load properly (e.g. syntax error).
            eval { $object->config_as_hash; };
            if ($@) {
                # Module failed to load, print error and add to failed
                # modules list.
                print STDERR "Problem loading module $current\n";
                print STDERR "This module will not be available\n";
                $self->{'modstatus'} .= "$current ";
            }
        }

      } elsif (/^\s*\}\s*$/) {
{'fraction_non_alphanumeric': 0.19127173542448006, 'fraction_numerical': 0.00477326968973747, 'mean_word_length': 1.9786802030456854, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '470529', 'n_tokens_mistral': 1015, 'n_tokens_neox': 972, 'n_words': 266}