--- Utils.pm.orig 2003-09-19 17:15:54.000000000 +0100 +++ Utils.pm 2003-09-19 17:16:49.000000000 +0100 @@ -5,10 +5,12 @@ $VERSION = '0.05'; use Carp qw( croak ); +use Config::Tiny; use CGI::Wiki; use CGI::Wiki::Formatter::UseMod; use CGI::Wiki::Search::SII; use Search::InvertedIndex::DB::DB_File_SplitHash; +use Template; use URI::Escape; =head1 NAME @@ -111,6 +113,48 @@ return $wiki; } +=item B + + my $config = OpenGuides::Utils->make_config_object(); + +Returns a C object containing the configuration for +the current OpenGuides site. Assumes that the conf folder is +located one level up from the current working directory. + +Finds the site-specific configfile by evaluating a TT2 template +stored in the generic config file as item 'config'. This template +has access to the arrays @domain and @path. + +=cut + +sub make_config_object { + croak "Can't find the common openguides config file" + unless -r '../conf/openguides'; + + my $common_config = Config::Tiny->read('../conf/openguides'); + my @domain = $ENV{SERVER_NAME} =~ m{([^.]+).?}g; + my @path = $ENV{SCRIPT_NAME} =~ m{/([^/]+)}g; + + croak "Name of site-specific OpenGuides config file not supplied" + unless exists $common_config->{_}->{config} and + defined $common_config->{_}->{config}; + + my $tt = Template->new(); + my $site_config_template = $common_config->{_}->{config}; + my $site_config = ''; + $tt->process(\$site_config_template, + { domain => \@domain, path => \@path }, + \$site_config); + + croak "Invalid site-specific OpenGuides config file supplied" + unless defined $site_config; + + croak "Can't find the site-specific OpenGuides config file ($site_config)" + unless -r "../conf/$site_config"; + + my $config = Config::Tiny->read("../conf/$site_config"); + return $config; +} =back