Config.pm 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. Reads $home_cfg, falling back to $default when the instance has never saved a
  13. configuration of its own. Both are full paths relative to the tCMS root, so
  14. that writers can use them too -- an earlier version had the 'config/' prefix
  15. hardcoded here and nowhere else, which meant everything that *wrote* the
  16. configuration put it somewhere get() would never look.
  17. =cut
  18. # Where an instance's own configuration lives, once it has saved one.
  19. our $home_cfg = "config/main.cfg";
  20. # Shipped defaults. Tracked in git -- never write to this.
  21. our $default = "config/default.cfg";
  22. sub get {
  23. state $cf;
  24. return $cf if $cf;
  25. foreach my $cfg2try ($home_cfg, $default) {
  26. next unless -f $cfg2try;
  27. $cf = Config::Simple->new($cfg2try);
  28. last;
  29. }
  30. die "Could not find config file!" unless $cf;
  31. return $cf;
  32. }
  33. 1;