XppConfig.pm 830 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package XppConfig;
  2. #
  3. # Written by Oron Peled <oron@actcom.co.il>
  4. # Copyright (C) 2008, Xorcom
  5. # This program is free software; you can redistribute and/or
  6. # modify it under the same terms as Perl itself.
  7. #
  8. # $Id$
  9. #
  10. use strict;
  11. my $conf_file = "/etc/dahdi/xpp.conf";
  12. sub import {
  13. my $pack = shift || die "Import without package?";
  14. my $init_dir = shift || die "$pack::import -- missing init_dir parameter";
  15. my $local_conf = "$init_dir/xpp.conf";
  16. $conf_file = $local_conf if -r $local_conf;
  17. }
  18. sub read_config($) {
  19. my $opts = shift || die;
  20. open(F, $conf_file) || return ();
  21. while(<F>) {
  22. chomp;
  23. s/#.*//; # strip comments
  24. next unless /\S/;
  25. s/\s*$//; # Trim trailing whitespace
  26. my ($key, $value) = split(/\s+/, $_, 2);
  27. $opts->{$key} = $value;
  28. }
  29. close F;
  30. $opts->{'xppconf'} = $conf_file;
  31. return %{$opts};
  32. }
  33. 1;