12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package Trog::Config;
- use strict;
- use warnings;
- no warnings 'experimental';
- use feature qw{signatures};
- use Config::Tiny;
- =head1 Trog::Config
- A thin wrapper around Config::Simple which reads the configuration from the appropriate place.
- =head2 Trog::Config::get() = Config::Tiny
- Returns a configuration object that will be used by server.psgi, the data model and Routing modules.
- The object will be cached in memory, so that re-run of get() will return the object fetched earlier.
- Pass in a truthy argument to force refetch.
- =cut
- our $home_cfg = "config/main.cfg";
- my $cf;
- sub get {
- my ($refetch) = @_;
- undef $cf if $refetch;
- return $cf if $cf;
- $cf = Config::Tiny->read($home_cfg) if -f $home_cfg;
- return $cf if $cf;
- $cf = Config::Tiny->read('config/default.cfg');
- return $cf;
- }
- =head2 Trog::Config::theme_dir()
- Returns string corresponding to the path of the theme in use per config.
- The string will be cached in memory, so that re-run of get() will return the object fetched earlier.
- Pass in a truthy argument to force refetch of both theme dir and config object.
- =cut
- my $theme_dir = '';
- sub theme_dir {
- my ($refetch) = @_;
- $theme_dir = '' if $refetch;
- return $theme_dir if $theme_dir;
- get($refetch) if !$cf || $refetch;
- $theme_dir = "themes/$cf->{'general'}{'theme'}" if $cf->{'general'}{'theme'} && -d "www/themes/$cf->{'general'}{'theme'}";
- return $theme_dir;
- }
- 1;
|