Audio-Nama

 view release on metacpan or  search on metacpan

lib/Audio/Nama/Config.pm  view on Meta::CPAN

# ------ Config subroutines ------

# To create a new config var:
#
# add the mapping, e.g. "$mix_to_disk_format $config->{mix_to_disk_format}"
# (without quotes) to file var_config

# these subs are in the main namespace

package Audio::Nama;

use Modern::Perl '2020';
no warnings 'uninitialized';

use Audio::Nama::Globals qw(:all);

# exclusive to this module
our ( 
	%subst,			# substitutions		
);

## configuration file

sub global_config {

	# return text of config file, in the following order
	# or priority:
	#
	# 1. the file designated by the -f command line argument
	# 2. .namarc in the current project directory, i.e. ~/nama/untitled/.namarc
	# 3. .namarc in the home directory, i.e. ~/.namarc
	# 4. .namarc in the project root directory, i.e. ~/nama/.namarc
	if( $config->{opts}->{f} ){
		pager_newline("reading config file $config->{opts}->{f}\n");
		return read_file($config->{opts}->{f});
	}
	my @search_path = (project_dir(), $ENV{HOME}, project_root() );
	my $c = 0;
		map{ 
				if (-d $_) {
					my $config_path = join_path($_, config_file());
					if( -f $config_path or -l $config_path){ 
						say "Found config file: $config_path";
						my $yml = read_file($config_path);
						return $yml;
					}
				}
			} ( @search_path) 
}

# sub global_config {
# 	read_file( join_path($ENV{HOME}, config_file()));
# }

sub read_config {

	# read and process the configuration file
	#
	# use the embedded default file if none other is present
	
	logsub((caller(0))[3]);
	
	my $config_file = shift;
	
	my $yml = $config_file // get_data_section("default_namarc");
	strip_all( $yml );
	my %cfg = %{  yaml_in($yml) };
	logpkg(__FILE__,__LINE__,'debug', "config file:", Dumper \%cfg);
	*subst = \%{$cfg{abbreviations}}; # alias
	walk_tree(\%cfg);
	walk_tree(\%cfg); # second pass completes substitutions
	assign( 

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.434 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )