14 |
|
|
15 |
=head1 VERSION |
=head1 VERSION |
16 |
|
|
17 |
Version 0.01 |
Version 0.02 |
18 |
|
|
19 |
=cut |
=cut |
20 |
|
|
21 |
our $VERSION = '0.01'; |
our $VERSION = '0.02'; |
22 |
|
|
23 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
24 |
|
|
30 |
|
|
31 |
Create new configuration object. |
Create new configuration object. |
32 |
|
|
33 |
|
my $config = new WebPAC::Config( |
34 |
|
path => '/optional/path/to/config.yml' |
35 |
|
); |
36 |
|
|
37 |
=cut |
=cut |
38 |
|
|
39 |
sub new { |
sub new { |
55 |
|
|
56 |
$self->{path} ||= 'conf/config.yml'; |
$self->{path} ||= 'conf/config.yml'; |
57 |
|
|
58 |
|
$log->logdie("can't open ", $self->{path}, ": $!") if ! -r $self->{path}; |
59 |
|
|
60 |
$self->{config} = LoadFile($self->{path}) || |
$self->{config} = LoadFile($self->{path}) || |
61 |
$log->logdie("can't open ",$self->{path}, ": $!"); |
$log->logdie("can't open ",$self->{path}, ": $!"); |
62 |
|
|
67 |
|
|
68 |
=head2 databases |
=head2 databases |
69 |
|
|
70 |
|
Return all databases in config |
71 |
|
|
72 |
my $config_databases_hash = $config->databases; |
my $config_databases_hash = $config->databases; |
73 |
my @config_databases_names = $config->databases; |
my @config_databases_names = $config->databases; |
74 |
|
|
86 |
|
|
87 |
=head2 use_indexer |
=head2 use_indexer |
88 |
|
|
89 |
|
Which indexer are we using? |
90 |
|
|
91 |
$config->use_indexer; |
$config->use_indexer; |
92 |
|
|
93 |
=cut |
=cut |
94 |
|
|
95 |
sub use_indexer { |
sub use_indexer { |
96 |
my $self = shift; |
my $self = shift; |
|
my $default = 'hyperestraier'; |
|
97 |
return unless ($self->{config}); |
return unless ($self->{config}); |
98 |
return $self->{config}->{use_indexer} || $default; |
return $self->{config}->{use_indexer} || undef; |
99 |
} |
} |
100 |
|
|
101 |
=head2 get |
=head2 get |
134 |
|
|
135 |
} |
} |
136 |
|
|
137 |
|
=head2 iterate_inputs |
138 |
|
|
139 |
|
$config->iterate_inputs( sub { |
140 |
|
my ($input, $database, $database_config_hash) = @_; |
141 |
|
# ... do something with input config hash |
142 |
|
} ); |
143 |
|
|
144 |
|
This function will also modify C<< $input->{normalize} >> to |
145 |
|
be C<ARRAY>, even with just one element. |
146 |
|
|
147 |
|
=cut |
148 |
|
|
149 |
|
sub iterate_inputs { |
150 |
|
my $self = shift; |
151 |
|
|
152 |
|
my $log = $self->_get_logger(); |
153 |
|
|
154 |
|
my $code_ref = shift; |
155 |
|
$log->logdie("called with CODE") unless ( ref($code_ref) eq 'CODE' ); |
156 |
|
|
157 |
|
while (my ($database, $db_config) = each %{ $self->{config}->{databases} }) { |
158 |
|
my @inputs; |
159 |
|
if (ref($db_config->{input}) eq 'ARRAY') { |
160 |
|
@inputs = @{ $db_config->{input} }; |
161 |
|
} elsif ($db_config->{input}) { |
162 |
|
push @inputs, $db_config->{input}; |
163 |
|
} else { |
164 |
|
$log->info("database $database doesn't have inputs defined"); |
165 |
|
} |
166 |
|
|
167 |
|
foreach my $input (@inputs) { |
168 |
|
$log->debug("iterating over input ", dump($input)); |
169 |
|
if ( defined( $input->{normalize} ) && ref($input->{normalize}) ne 'ARRAY' ) { |
170 |
|
$input->{normalize} = [ $input->{normalize} ]; |
171 |
|
} |
172 |
|
$code_ref->($input, $database, $db_config); |
173 |
|
} |
174 |
|
} |
175 |
|
|
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
=head1 AUTHOR |
=head1 AUTHOR |
180 |
|
|
181 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |