/usr/share/perl5/Lire/Config.pm is in lire 2:2.1.1-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | package Lire::Config;
use strict;
use vars qw/ $VERSION $PACKAGE $SINGLETON /;
use Lire::Config::Build qw(ac_info ac_path);
use Carp;
=pod
=head1 NAME
Lire::Config - import Lire configuration variables to perl
=head1 SYNOPSIS
use Lire::Config;
Lire::Config->init();
my $cfg->value = Lire::Config->get( 'lr_schemas_path' );
my $var = Lire::Config->get_var( 'lr_schemas_path' );
=head1 DESCRIPTION
This package provides the API to access the Lire configuration.
=head1 METHODS
These methods can be called directly on a Lire::Config instance or the
Lire::Config package itself. In the last case, it is the same thing
as calling the method on the object returned by the instance()
method.
=cut
$SINGLETON = new Lire::Config::XMLFilesConfig();
sub lire_program_config_init {
$SINGLETON->init();
init_vars();
}
sub init_vars {
# VERSION does not hold this module's version, but the Lire version.
# ($VERSION) = '$Release:$' =~ m!Release: ([.\d]+)!;
$VERSION = ac_info('VERSION');
$PACKAGE = ac_info('PACKAGE');
}
=pod
=head2 instance()
Returns the singleton Lire::Config object from which configuration can
be queried.
=cut
sub instance {
return $SINGLETON;
}
BEGIN {
no strict 'refs';
# Autogenerate methods which delegates to the singleton.
foreach my $method ( qw/ init config_spec config_spec_path
add_config_spec_path_dir del_config_spec_path_dir
add_config_path
add_config_file del_config_file config_files
get_config_file
get get_var / )
{
*{$method} = sub { my $pkg = shift; $SINGLETON->$method( @_ ) };
}
}
package Lire::Config::XMLFilesConfig;
use base qw/ Lire::Config /;
use Lire::Config::Parser;
use Lire::Config::SpecParser;
use Lire::Utils qw/ tilde_expand check_param /;
use Lire::Error qw/ directory_not_readable /;
use Lire::Config::Build 'ac_path';
use Carp;
sub new {
my $proto = shift;
my $class = ref( $proto ) || $proto;
my $self =
bless {
'_config_spec_dirs' => [ ac_path('datadir', 'PACKAGE') . "/config-spec" ],
'_config_files' => [],
'_parsed_config' => {},
'_defaults' => undef,
'_spec' => undef,
}, $class;
my @dirs = ( ac_path('datadir', 'PACKAGE') ."/defaults",
ac_path('sysconfdir', 'PACKAGE') . "/config",
tilde_expand( "~/.lire/config" )
);
foreach my $dir ( @dirs ) {
next unless -d $dir;
$self->add_config_path( $dir );
}
my $cfg_file = tilde_expand( "~/.lire/config.xml" );
$self->add_config_file( $cfg_file )
if -f $cfg_file;
return $self;
}
=pod
=head2 config_spec()
Returns the configuration specification used by the current
configuration.
=cut
sub config_spec {
my $self = $_[0];
croak( "config_spec() called while configuration wasn't initialized" )
unless $self->{'_spec'};
return $self->{'_spec'};
}
=pod
=head2 config_spec_path()
Returns a list of directories which will be searched for configuration
specification file. By default, configuration specifications are only
looked for in F<<datadir>/lire/config-spec>.
=cut
sub config_spec_path {
return @{$_[0]->{'_config_spec_dirs'}};
}
=pod
=head2 add_config_spec_path_dir( $dir )
This method adds a directory to list of directories that will is used
to search for configuration specification files.
=cut
sub add_config_spec_path_dir {
my ( $self, $dir ) = @_;
croak "missing 'dir' argument"
unless $dir;
unshift @{$self->{'_config_spec_dirs'}}, $dir;
delete $self->{'_spec'};
return;
}
=pod
=head2 del_config_spec_path_dir( $dir )
This method removes a directory from the list of directories that is
used to search for configuration specification files.
=cut
sub del_config_spec_path_dir {
my ( $self, $dir ) = @_;
croak "missing 'dir' argument"
unless $dir;
@{$self->{'_config_spec_dirs'}} =
grep { $_ ne $dir } $self->config_spec_path();
delete $self->{'_spec'};
return;
}
=pod
=head2 config_files()
Returns the list of configuration files that will be used for this
configuration.
=cut
sub config_files {
my ( $self, $dir ) = @_;
return @{$self->{'_config_files'}}
}
sub _find_config_files {
my $self = shift;
my @files;
foreach(@_) {
if(-d) {
opendir DIR, $_
or croak directory_not_readable( $_ );
my @ents = grep { !/^\./ } readdir DIR;
closedir DIR;
my $d = $_;
push @files, map { "$d/$_" } $self->_find_config_files(@ents);
} else {
push @files, $_
if !/^[.#]/ && /\.xml$/;
}
}
return @files;
}
=pod
=head2 add_config_path( $path )
Adds configuration files to the list of files that are part of the
configuration. Directories will be scanned recursively.
=cut
sub add_config_path {
my ( $self, $path ) = @_;
check_param( $path, 'path' );
foreach ( $self->_find_config_files( $path ) ) {
$self->add_config_file( $_ );
}
return;
}
=pod
=head2 add_config_file( $file )
Adds a configuration file to the list of files that will be parsed to
initialize the configuration.
=cut
sub add_config_file {
my ( $self, $file ) = @_;
check_param( $file, 'file' );
push @{$self->{'_config_files'}}, $file;
$self->_load_config_file( $file ) if $self->{'_spec'};
return;
}
=pod
=head2 del_config_file( $file )
Removes a configuration file from the list of files that are part of
the configuration.
=cut
sub del_config_file {
my ( $self, $file ) = @_;
check_param( $file, 'file' );
@{$self->{'_config_files'}} = grep { $_ ne $file } $self->config_files();
delete $self->{'_parsed_config'}{$file};
return;
}
=pod
=head2 get_config_file($file)
Get a parsed configuration file object from the list of files.
=cut
sub get_config_file {
my ( $self, $file ) = @_;
check_param( $file, 'file' );
croak("file '$file' is not a known configuration file")
unless exists $self->{'_parsed_config'}{$file};
return $self->{'_parsed_config'}{$file};
}
=pod
=head2 init()
This method loads and parses the configuration files. It should be called
prior to using the get() method to obtain configuration data. This
method will throw an exception in case there is an invalid
parameter in the configuration.
=cut
sub init {
my $self = $_[0];
return if $self->{'_spec'};
$self->_load_spec();
$self->_load_config_files();
return;
}
=pod
=head2 get( $varname )
Returns the configuration value for the $varname configuration
variable. init() should have been called to load the configuration
data before using this method. It will croak() otherwise. If the
$varname is unknown, an exception will also be thrown.
=cut
sub get {
return shift->get_var( @_ )->as_value();
}
=pod
=head2 get_var( $varname )
Returns the configuration value for the $varname configuration
variable as the configuration object. init() should have been called
to load the configuration data before using this method. It will
croak() otherwise. If the $varname is unknown, an exception will also
be thrown.
=cut
sub get_var {
my ( $self, $name ) = @_;
croak( "Configuration queried without initialization" )
unless $self->{'_spec'};
croak "No such configuration variable: $name"
unless $self->{'_spec'}->has_component($name);
foreach my $file ( reverse $self->config_files() ) {
my $cfg = $self->{'_parsed_config'}{$file}->global();
return $cfg->get( $name )
if ( $cfg && $cfg->is_set( $name ) );
}
return $self->{'_defaults'}->get( $name );
}
sub _load_spec {
my $self = $_[0];
my $parser = new Lire::Config::SpecParser;
foreach my $dir ( $self->config_spec_path() ) {
$parser->merge_specifications_dir( $dir );
}
$self->{'_spec'} = $parser->configspec();
$self->{'_defaults'} = $self->{'_spec'}->instance();
return;
}
sub _load_config_files {
my $self = $_[0];
$self->{'_parsed_config'} = {};
foreach my $file ( $self->config_files() ) {
$self->_load_config_file( $file );
}
return;
}
sub _load_config_file {
my ( $self, $file ) = @_;
my $parser = new Lire::Config::Parser( 'spec' => $self->{'_spec'} );
$self->{'_parsed_config'}{$file} = $parser->load_config_file( $file );
return;
}
# keep perl happy
1;
__END__
=pod
=head1 DEBUGGING
One can call this module direct from the commandline, e.g. for debugging
purposes, by doing something like:
perl -e 'use lib "/path/to/your/share/perl5"; use Lire::Config; \
use Lire::Program; print Lire::Config->get( "lr_mail_from" ), "\n"'
or
perl -e 'use Lire::Config; use Lire::Program; \
$a = Lire::Config->get( lr_converters_init_path ); print "@$a\n"; '
.
=head1 SEE ALSO
Lire::Config::TypeSpec(3pm), Lire::Config::Value(3pm)
=head1 AUTHORS
Wessel Dankers <wsl@logreport.org>
Francis J. Lacoste <flacoste@logreport.org>
Joost van Baal <joostvb@logreport.org>
=head1 VERSION
$Id: Config.pm,v 1.47 2006/07/23 13:16:28 vanbaal Exp $
=head1 COPYRIGHT
Copyright (C) 2001-2004 Stichting LogReport Foundation LogReport@LogReport.org
This file is part of Lire.
Lire is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html.
=cut
|