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 { |
65 |
|
|
66 |
=head2 databases |
=head2 databases |
67 |
|
|
68 |
|
Return all databases in config |
69 |
|
|
70 |
my $config_databases_hash = $config->databases; |
my $config_databases_hash = $config->databases; |
71 |
my @config_databases_names = $config->databases; |
my @config_databases_names = $config->databases; |
72 |
|
|
84 |
|
|
85 |
=head2 use_indexer |
=head2 use_indexer |
86 |
|
|
87 |
|
Which indexer are we using? |
88 |
|
|
89 |
$config->use_indexer; |
$config->use_indexer; |
90 |
|
|
91 |
=cut |
=cut |
97 |
return $self->{config}->{use_indexer} || $default; |
return $self->{config}->{use_indexer} || $default; |
98 |
} |
} |
99 |
|
|
100 |
|
=head2 get |
101 |
|
|
102 |
|
$config->get('top-level_key'); |
103 |
|
|
104 |
|
=cut |
105 |
|
|
106 |
|
sub get { |
107 |
|
my $self = shift; |
108 |
|
my $what = shift || return; |
109 |
|
return $self->{config}->{$what}; |
110 |
|
} |
111 |
|
|
112 |
|
=head2 webpac |
113 |
|
|
114 |
|
Return C<< config -> webpac >> parts |
115 |
|
|
116 |
|
my @supported_inputs = $config->webpac('inputs'); |
117 |
|
my $inputs_hash = $config->webpac('inputs'); |
118 |
|
|
119 |
|
=cut |
120 |
|
|
121 |
|
sub webpac { |
122 |
|
my $self = shift; |
123 |
|
|
124 |
|
$self->_get_logger()->logdie("can't find config->webpac") unless defined( $self->{config}->{webpac} ); |
125 |
|
|
126 |
|
my $what = shift || return $self->{config}->{webpac}; |
127 |
|
|
128 |
|
if (wantarray && ref( $self->{config}->{webpac}->{$what} ) eq 'HASH') { |
129 |
|
return keys %{ $self->{config}->{webpac}->{$what} }; |
130 |
|
} else { |
131 |
|
return $self->{config}->{webpac}->{$what}; |
132 |
|
} |
133 |
|
|
134 |
|
} |
135 |
|
|
136 |
|
=head2 iterate_inputs |
137 |
|
|
138 |
|
$config->iterate_inputs( sub { |
139 |
|
my ($input, $database, $database_config_hash) = @_; |
140 |
|
# ... do something with input config hash |
141 |
|
} ); |
142 |
|
|
143 |
|
=cut |
144 |
|
|
145 |
|
sub iterate_inputs { |
146 |
|
my $self = shift; |
147 |
|
|
148 |
|
my $log = $self->_get_logger(); |
149 |
|
|
150 |
|
my $code_ref = shift; |
151 |
|
$log->logdie("called with CODE") unless ( ref($code_ref) eq 'CODE' ); |
152 |
|
|
153 |
|
while (my ($database, $db_config) = each %{ $self->{config}->{databases} }) { |
154 |
|
my @inputs; |
155 |
|
if (ref($db_config->{input}) eq 'ARRAY') { |
156 |
|
@inputs = @{ $db_config->{input} }; |
157 |
|
} elsif ($db_config->{input}) { |
158 |
|
push @inputs, $db_config->{input}; |
159 |
|
} else { |
160 |
|
$log->info("database $database doesn't have inputs defined"); |
161 |
|
} |
162 |
|
|
163 |
|
foreach my $input (@inputs) { |
164 |
|
$log->debug("iterating over input ", dump($input)); |
165 |
|
$code_ref->($input, $database, $db_config); |
166 |
|
} |
167 |
|
} |
168 |
|
|
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
=head1 AUTHOR |
=head1 AUTHOR |
173 |
|
|
174 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |