--- trunk/lib/WebPAC/Config.pm 2006/09/24 15:28:54 682 +++ trunk/lib/WebPAC/Config.pm 2006/09/24 17:24:59 685 @@ -30,6 +30,10 @@ Create new configuration object. + my $config = new WebPAC::Config( + path => '/optional/path/to/config.yml' + ); + =cut sub new { @@ -61,6 +65,8 @@ =head2 databases +Return all databases in config + my $config_databases_hash = $config->databases; my @config_databases_names = $config->databases; @@ -78,6 +84,8 @@ =head2 use_indexer +Which indexer are we using? + $config->use_indexer; =cut @@ -117,7 +125,7 @@ my $what = shift || return $self->{config}->{webpac}; - if (wantarray) { + if (wantarray && ref( $self->{config}->{webpac}->{$what} ) eq 'HASH') { return keys %{ $self->{config}->{webpac}->{$what} }; } else { return $self->{config}->{webpac}->{$what}; @@ -125,6 +133,42 @@ } +=head2 iterate_inputs + + $config->iterate_inputs( sub { + my $input = shift; + # ... do something with input config hash + } ); + +=cut + +sub iterate_inputs { + my $self = shift; + + my $log = $self->_get_logger(); + + my $code_ref = shift; + $log->logdie("called with CODE") unless ( ref($code_ref) eq 'CODE' ); + + while (my ($database, $db_config) = each %{ $self->{config}->{databases} }) { + my @inputs; + if (ref($db_config->{input}) eq 'ARRAY') { + @inputs = @{ $db_config->{input} }; + } elsif ($db_config->{input}) { + push @inputs, $db_config->{input}; + } else { + $log->info("database $database doesn't have inputs defined"); + } + + foreach my $input (@inputs) { + $log->debug("iterating over input ", dump($input)); + $code_ref->($input); + } + } + +} + + =head1 AUTHOR Dobrica Pavlinusic, C<< >>