r965@llin: dpavlin | 2006-09-24 18:07:03 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 24 Sep 2006 17:24:59 +0000 (17:24 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 24 Sep 2006 17:24:59 +0000 (17:24 +0000)
 added iterate_inputs

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@685 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Config.pm
t/1-config.t

index 8058d79..9e6f7af 100644 (file)
@@ -30,6 +30,10 @@ FIXME
 
 Create new configuration object.
 
+  my $config = new WebPAC::Config(
+       path => '/optional/path/to/config.yml'
+  );
+
 =cut
 
 sub new {
@@ -61,6 +65,8 @@ sub new {
 
 =head2 databases
 
+Return all databases in config
+
   my $config_databases_hash = $config->databases;
   my @config_databases_names = $config->databases;
 
@@ -78,6 +84,8 @@ sub databases {
 
 =head2 use_indexer
 
+Which indexer are we using?
+
   $config->use_indexer;
 
 =cut
@@ -125,6 +133,42 @@ sub webpac {
 
 }
 
+=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<< <dpavlin@rot13.org> >>
index f7ff11e..3dcc7b0 100755 (executable)
@@ -40,3 +40,8 @@ my @inputs = $config->webpac('inputs');
 diag "inputs = ",dump( @inputs ) if ($debug);
 isa_ok(\@inputs, 'ARRAY', "inputs");
 cmp_ok(@inputs, '==', 2, "got 2 webpac inputs");
+
+$config->iterate_inputs(sub {
+       my $input = shift;
+       diag "input = ",dump($input);
+});