<commit_before>package RSGet::Config;
# This file is an integral part of rsget.pl downloader.
#
# 2010 (c) <NAME> <<EMAIL>>
#		This program is free software,
# you may distribute it under GPL v2 or newer.

use strict;
use warnings;

RSGet::Config::register_settings(
	config_dir => {
		desc => "Main config directory.",
		default => '${HOME}/.rsget.pl',
	},
	config_file => {
		desc => "Main config file.",
		default => '%{config_dir}/config',
	},
	# escape secuences
	p => {
		default => "%",
	},
	s => {
		default => "\$",
	},
	n => {
		default => "\n",
	},
	nil => {
		default => "",
	},
);

# initalized ?
my $init = 0;

# registered settings
my %registered;

# most actual options possible
my %options;

use constant {
	OPT_USER	=> 0,
	OPT_KEY		=> 1,
	OPT_VALUE	=> 2,
	OPT_PRIO	=> 3,
	OPT_ORIGIN	=> 4,
};

# prioroty (from highest to lowest)
use constant {
	PRIO_RUNTIME	=> 0,	# runtime changed
	PRIO_ARGS		=> 1,	# commandline arguments
	PRIO_DYNAMIC	=> 2,	# dynamic config
	PRIO_STATIC		=> 3,	# static config file
	PRIO_DEFAULT	=> 4,	# default value
};

# {{{ sub register_settings: add settings to register hash
use constant _regdata => {
	desc	=> "Setting description.",
	default	=> "Default value.",
	allowed	=> "RegExp that defines allowed values.",
	dynamic	=> "May be changed after start.",
	type	=> "Type of the setting.",
	user	=> "May be modified by user.",
	novalue	=> "Option is set to this value if no argument is specified.",
};

sub register_settings
{
	while ( my ($k, $v) = splice @_, 0, 2 ) {
		die "RSGet::Config: Setting for '$k' is not a HASH\n"
			unless ref $v eq "HASH";
		foreach ( keys %$v ) {
			die "RSGet::Config: Setting '$k' has unknown option: $_\n"
				unless exists _regdata->{ $_ };
		}

		$registered{ $k } = $v;

		_set( undef, $k, $v->{default}, PRIO_DEFAULT,
			"default setting" );
	}
}
# }}}

# {{{ sub reqister_dynaconfig: register object used to read and write config
# $dynaconfig object must have 2 methods:
#	->set( $user, $key, $value );
#	->getall();
my $dynaconfig;
sub reqister_dynaconfig
{
	$dynaconfig = shift;
	_init_dynaconfig()
		if $init;
}
# }}}

# {{{ sub get: get and expand one macro
sub _get_raw
{
	my $user = shift;
	my $key = shift;
	my $local = shift;

	my $value;
	if ( $local ) {
		$value = $local->{ $key };
	}
	if ( not defined $value ) {
		my $macro = undef;
		if ( $user ) {
			my $ukey = $user . ":" . $key;
			$macro = $options{ $ukey };
		}
		$macro = $options{ $key }
			unless $macro;
	<commit_msg>- fixed typo<commit_after>package RSGet::Config;
# This file is an integral part of rsget.pl downloader.
#
# 2010 (c) <NAME> <<EMAIL>>
#		This program is free software,
# you may distribute it under GPL v2 or newer.

use strict;
use warnings;

RSGet::Config::register_settings(
	config_dir => {
		desc => "Main config directory.",
		default => '${HOME}/.rsget.pl',
	},
	config_file => {
		desc => "Main config file.",
		default => '%{config_dir}/config',
	},
	# escape secuences
	p => {
		default => "%",
	},
	s => {
		default => "\$",
	},
	n => {
		default => "\n",
	},
	nil => {
		default => "",
	},
);

# initalized ?
my $init = 0;

# registered settings
my %registered;

# most actual options possible
my %options;

use constant {
	OPT_USER	=> 0,
	OPT_KEY		=> 1,
	OPT_VALUE	=> 2,
	OPT_PRIO	=> 3,
	OPT_ORIGIN	=> 4,
};

# prioroty (from highest to lowest)
use constant {
	PRIO_RUNTIME	=> 0,	# runtime changed
	PRIO_ARGS		=> 1,	# commandline arguments
	PRIO_DYNAMIC	=> 2,	# dynamic config
	PRIO_STATIC		=> 3,	# static config file
	PRIO_DEFAULT	=> 4,	# default value
};

# {{{ sub register_settings: add settings to register hash
use constant _regdata => {
	desc	=> "Setting description.",
	default	=> "Default value.",
	allowed	=> "RegExp that defines allowed values.",
	dynamic	=> "May be changed after start.",
	type	=> "Type of the setting.",
	user	=> "May be modified by user.",
	novalue	=> "Option is set to this value if no argument is specified.",
};

sub register_settings
{
	while ( my ($k, $v) = splice @_, 0, 2 ) {
		die "RSGet::Config: Setting for '$k' is not a HASH\n"
			unless ref $v eq "HASH";
		foreach ( keys %$v ) {
			die "RSGet::Config: Setting '$k' has unknown option: $_\n"
				unless exists _regdata->{ $_ };
		}
		die "RSGet::Config: Setting '$k' has no default value.\n"
			unless exists $v->{default};

		$registered{ $k } = $v;

		_set( undef, $k, $v->{default}, PRIO_DEFAULT,
			"default setting" );
	}
}
# }}}

# {{{ sub register_dynaconfig: register object used to read and write config
# $dynaconfig object must have 2 methods:
#	->set( $user, $key, $value );
#	->getall();
my $dynaconfig;
sub register_dynaconfig
{
	$dynaconfig = shift;
	_init_dynaconfig()
		if $init;
}
# }}}

# {{{ sub get: get and expand one macro
sub _get_raw
{
	my $user = shift;
	my $key = shift;
	my $local = shift;

	my $value;
	if ( $local ) {
		$value = $local->{ $key };
	}
	if ( not defined $value ) {
		my $macro = undef;
		if ( $user ) {
			my $ukey = $user . ":" . $key;
			$macro = $options{ $ukey };
		}
		$macro = $options{ $key }
			unless $macro;
	
{'fraction_non_alphanumeric': 0.16623736873390133, 'fraction_numerical': 0.007529225282345948, 'mean_word_length': 3.378143972246314, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '455454', 'n_tokens_mistral': 2022, 'n_tokens_neox': 1875, 'n_words': 587}