Config.pm 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package Trog::Config;
  2. use v5.36;
  3. use re '/aa';
  4. use FindBin::libs;
  5. use Config::Simple;
  6. =head1 Trog::Config
  7. A thin wrapper around Config::Simple which reads the configuration from the appropriate place.
  8. =head2 Trog::Config::get() = Config::Simple
  9. Returns a configuration object that will be used by server.psgi, the data model and Routing modules.
  10. Memoized, so you will need to HUP the children on config changes.
  11. Reads $home_cfg, falling back to $default when the instance has never saved a
  12. configuration of its own. Both are full paths relative to the tCMS root, so
  13. that writers can use them too -- an earlier version had the 'config/' prefix
  14. hardcoded here and nowhere else, which meant everything that *wrote* the
  15. configuration put it somewhere get() would never look.
  16. =cut
  17. # Where an instance's own configuration lives, once it has saved one.
  18. our $home_cfg = "config/main.cfg";
  19. # Shipped defaults. Tracked in git -- never write to this.
  20. our $default = "config/default.cfg";
  21. sub get {
  22. state $cf;
  23. return $cf if $cf;
  24. foreach my $cfg2try ($home_cfg, $default) {
  25. next unless -f $cfg2try;
  26. $cf = Config::Simple->new($cfg2try);
  27. last;
  28. }
  29. die "Could not find config file!" unless $cf;
  30. return $cf;
  31. }
  32. 1;