Config.pm 819 B

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