<commit_before>#!perl
#This program is free software. You may redistribute it under the terms of the Artistic License 2.0.
package UserPrefs;

use 5.012;
use warnings;

our $VERSION = v1;

use Log;

my $l = Log->new();
our $FILE = 'userprefs.ini';
my %data;
my $changed = 0;

#initialises the preferences
sub init {
	$l->trace('initialising userprefs');
	unless (-e $main::DIRDATA.$FILE) {
		%data = ();
		return 1;
	}
	my $block;
	open (my $fh, '<', $main::DIRDATA.$FILE);
	while (my $line = <$fh>) {
		if ($line =~ /^\s*\[\s*(?<block>\w+)\s*\]\s*$/) {
			$block = $+{block};
			next;
		}
		next if $line =~ /^\s*\[;#]/;
		next if $line =~ /^\s*$/;
		next if length $line == 0;
		
		my ($what,$is) = split(/=/, $line, 2);
		$what =~ s/^\s*//g;
		$what =~ s/\s*$//g;
		$is =~ s/^\s*//g;
		$is =~ s/\s*$//g;
		
		$data{$block}->{$what} = $is;
	}
	close ($fh);
	return 1;
}

#$class, $sect -> $self
#returns the handle to a section
sub section {
	my ($class,$sect) = @_;
	$l->trace("userprefs handle for $sect"); 
	unless ($data{$sect}) {
		$l->debug("create $sect");
		$data{$sect} = {};
	}
	return bless \$sect, $class;
}

#$self|$section,$key -> $value
#returns the stored value
sub get {
	my ($sect,$key) = @_;
	$sect = $$sect if ref $sect;
	my $value = $data{$sect}->{$key};
	return $value;
}

#$self,$key,$value
#sets the value of key
sub set {
	my ($s,$key,$value) = @_;
	$l->trace("set key: $key to value: $value");<commit_msg>made section called without parameter use the module name of the caller<commit_after>#!perl
#This program is free software. You may redistribute it under the terms of the Artistic License 2.0.
package UserPrefs;

use 5.012;
use warnings;

our $VERSION = v1;

use Log;

my $l = Log->new();
our $FILE = 'userprefs.ini';
my %data;
my $changed = 0;

#initialises the preferences
sub init {
	$l->trace('initialising userprefs');
	unless (-e $main::DIRDATA.$FILE) {
		%data = ();
		return 1;
	}
	my $block;
	open (my $fh, '<', $main::DIRDATA.$FILE);
	while (my $line = <$fh>) {
		if ($line =~ /^\s*\[\s*(?<block>\w+)\s*\]\s*$/) {
			$block = $+{block};
			next;
		}
		next if $line =~ /^\s*\[;#]/;
		next if $line =~ /^\s*$/;
		next if length $line == 0;
		
		my ($what,$is) = split(/=/, $line, 2);
		$what =~ s/^\s*//g;
		$what =~ s/\s*$//g;
		$is =~ s/^\s*//g;
		$is =~ s/\s*$//g;
		
		$data{$block}->{$what} = $is;
	}
	close ($fh);
	return 1;
}

#$class, $sect -> $self
#returns the handle to a section
sub section {
	my ($class,$sect) = @_;
	$l->trace("userprefs handle for $sect"); 
	$sect //= caller; #/ padre display bug
	unless ($data{$sect}) {
		$l->debug("create $sect");
		$data{$sect} = {};
	}
	return bless \$sect, $class;
}

#$self|$section,$key -> $value
#returns the stored value
sub get {
	my ($sect,$key) = @_;
	$sect = $$sect if ref $sect;
	my $value = $data{$sect}->{$key};
	return $value;
}

#$self,$key,$value
#sets the value of key
sub set {
	my ($s,$key,$value) = @_;
	$l->trace("set key: $key to value: $value");
{'fraction_non_alphanumeric': 0.23987854251012145, 'fraction_numerical': 0.008097165991902834, 'mean_word_length': 3.3284671532846715, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, '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': '2707812', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1213, 'n_words': 341}