package Algebra::Config; use strict; require Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @ISA = qw(Exporter); @EXPORT= qw( get_config_var get_data_dir get_algebra_root ); @EXPORT_OK = qw( get_config_var ); $VERSION = 2000.0426; use vars qw( $algebra_data_dir ); sub get_algebra_root { my $algebra_root = $ENV{'ALGEBRA_ROOT'} || die "Webmaster has to define ALGEBRA_ROOT environment variable!"; return $algebra_root; } sub get_config_var { my ($category, $variable) = @_; my $algebra_root = get_algebra_root; my $config_file = "$algebra_root/etc/$category"; die "Config file '$config_file' does not exist or is not readable." unless -r $config_file; open( CONFIG, $config_file ); while( $_ = ) { chomp; next if( /^\s*#/ ); next if( /^\s*$/ ); my( $key, $value ) = split( /\s*=\s*/, $_ ); return $value if( $key eq $variable ); } return undef; } $algebra_data_dir = get_config_var( "general", "algebra_data_dir" ) || $ENV{'ALGEBRA_ROOT'}; sub get_data_dir { my ($category, $variable) = @_; my $dir = get_config_var( $category, $variable ); if( !($dir =~ /^\// ) ) { $dir = $algebra_data_dir . "/$dir"; } return $dir; } 1;