Config.pm 794 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package Trog::Config;
  2. use strict;
  3. use warnings;
  4. use feature qw{state};
  5. use FindBin::libs;
  6. use Config::Simple;
  7. =head1 Trog::Config
  8. A thin wrapper around Config::Simple which reads the configuration from the appropriate place.
  9. =head2 Trog::Config::get() = Config::Simple
  10. Returns a configuration object that will be used by server.psgi, the data model and Routing modules.
  11. Memoized, so you will need to HUP the children on config changes.
  12. =cut
  13. our $home_cfg = "main.cfg";
  14. our $default = "default.cfg";
  15. sub get {
  16. state $cf;
  17. return $cf if $cf;
  18. foreach my $cfg2try ($home_cfg, $default) {
  19. next unless -f "config/$cfg2try";
  20. $cf = Config::Simple->new("config/$cfg2try");
  21. last;
  22. }
  23. die "Could not find config file!" unless $cf;
  24. return $cf;
  25. }
  26. 1;