/[webpac2]/trunk/lib/WebPAC/Config.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/WebPAC/Config.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 681 - (show annotations)
Sun Sep 24 15:28:49 2006 UTC (17 years, 7 months ago) by dpavlin
File size: 1750 byte(s)
 r957@llin:  dpavlin | 2006-09-24 17:03:52 +0200
 move parts of configuration handling to WebPAC::Config

1 package WebPAC::Config;
2
3 use warnings;
4 use strict;
5
6 use base qw/WebPAC::Common/;
7
8 use Data::Dump qw/dump/;
9 use YAML qw/LoadFile/;
10
11 =head1 NAME
12
13 WebPAC::Config - handle WebPAC configuration file
14
15 =head1 VERSION
16
17 Version 0.01
18
19 =cut
20
21 our $VERSION = '0.01';
22
23 =head1 SYNOPSIS
24
25 FIXME
26
27 =head1 FUNCTIONS
28
29 =head2 new
30
31 Create new configuration object.
32
33 =cut
34
35 sub new {
36 my $class = shift;
37 my $self = {@_};
38 bless($self, $class);
39
40 my $log = $self->_get_logger();
41
42 if (! $self->{path}) {
43 my $hostname = `hostname`;
44 chomp($hostname);
45 $hostname =~ s/\..+$//;
46 if (-e "conf/$hostname.yml") {
47 $self->{path} = "conf/$hostname.yml";
48 $log->info("using host configuration file: ", $self->{path});
49 }
50 }
51
52 $self->{path} ||= 'conf/config.yml';
53
54 $self->{config} = LoadFile($self->{path}) ||
55 $log->logdie("can't open ",$self->{path}, ": $!");
56
57 $log->debug("config: ", dump( $self->{config} ));
58
59 $self ? return $self : return undef;
60 }
61
62 =head2 databases
63
64 my $config_databases_hash = $config->databases;
65 my @config_databases_names = $config->databases;
66
67 =cut
68
69 sub databases {
70 my $self = shift;
71 return unless ($self->{config});
72 if (wantarray) {
73 return keys %{ $self->{config}->{databases} };
74 } else {
75 return $self->{config}->{databases};
76 }
77 }
78
79 =head2 use_indexer
80
81 $config->use_indexer;
82
83 =cut
84
85 sub use_indexer {
86 my $self = shift;
87 my $default = 'hyperestraier';
88 return unless ($self->{config});
89 return $self->{config}->{use_indexer} || $default;
90 }
91
92 =head1 AUTHOR
93
94 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
95
96 =head1 COPYRIGHT & LICENSE
97
98 Copyright 2006 Dobrica Pavlinusic, All Rights Reserved.
99
100 This program is free software; you can redistribute it and/or modify it
101 under the same terms as Perl itself.
102
103 =cut
104
105 1; # End of WebPAC::Config

  ViewVC Help
Powered by ViewVC 1.1.26