| Buscador documentation | Contained in the Buscador distribution. |
Buscador::Config - provide config values
use Buscador::Config;
print Buscador::Config->dsn;
This works out the current directory (dependent on whether
the module is working under Apache or not), reads in a
buscador.config file and turns every key=value pair
into a subroutine Buscador::Config-key>.
Simon Wistow, <simon@thegestalt.org>
Copyright 2004, Simon Wistow
| Buscador documentation | Contained in the Buscador distribution. |
package Buscador::Config; use strict; use vars qw(%config); use Apache; use Carp qw(croak); use Cwd; BEGIN { my $home; # h-h-h-ack! eval { my $r = Apache->request; $home = $r->document_root.$r->location; }; if ($@) { $home = getcwd(); } chdir $home; $config{home} = $home; open (CONF, "buscador.config") || die "Can't open config file: $!\n"; while (<CONF>) { chomp; next if /^\s*#/; next if /^\s*$/; s!(^\s*|\s*$)!!; my ($key, $val) = split /\s*=\s*/, $_, 2; $config{$key} = $val; } close CONF; } sub AUTOLOAD { our ($AUTOLOAD); no strict 'refs'; my $tag = $AUTOLOAD; $tag =~s/.*:://; my $joined = join ",", keys %config; croak "No such method $tag try one of $joined" unless $config{$tag}; *$AUTOLOAD = sub { my $self = shift; if (@_) { my $val = shift; $config{$tag} = $val; return $val; } return $config{$tag}; }; goto &$AUTOLOAD; } 1; __END__