/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 682 by dpavlin, Sun Sep 24 15:28:54 2006 UTC revision 700 by dpavlin, Mon Sep 25 12:51:33 2006 UTC
# Line 14  WebPAC::Config - handle WebPAC configura Line 14  WebPAC::Config - handle WebPAC configura
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    
# Line 30  FIXME Line 30  FIXME
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 {
# Line 61  sub new { Line 65  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    
# Line 78  sub databases { Line 84  sub databases {
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
# Line 117  sub webpac { Line 125  sub webpac {
125    
126          my $what = shift || return $self->{config}->{webpac};          my $what = shift || return $self->{config}->{webpac};
127    
128          if (wantarray) {          if (wantarray && ref( $self->{config}->{webpac}->{$what} ) eq 'HASH') {
129                  return keys %{ $self->{config}->{webpac}->{$what} };                  return keys %{ $self->{config}->{webpac}->{$what} };
130          } else {          } else {
131                  return $self->{config}->{webpac}->{$what};                  return $self->{config}->{webpac}->{$what};
# Line 125  sub webpac { Line 133  sub webpac {
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    This function will also modify C<< $input->{normalize} >> to
144    be C<ARRAY>, even with just one element.
145    
146    =cut
147    
148    sub iterate_inputs {
149            my $self = shift;
150    
151            my $log = $self->_get_logger();
152    
153            my $code_ref = shift;
154            $log->logdie("called with CODE") unless ( ref($code_ref) eq 'CODE' );
155    
156            while (my ($database, $db_config) = each %{ $self->{config}->{databases} }) {
157                    my @inputs;
158                    if (ref($db_config->{input}) eq 'ARRAY') {
159                            @inputs = @{ $db_config->{input} };
160                    } elsif ($db_config->{input}) {
161                            push @inputs, $db_config->{input};
162                    } else {
163                            $log->info("database $database doesn't have inputs defined");
164                    }
165    
166                    foreach my $input (@inputs) {
167                            $log->debug("iterating over input ", dump($input));
168                            if ( defined( $input->{normalize} ) && ref($input->{normalize}) ne 'ARRAY' ) {
169                                    $input->{normalize} = [ $input->{normalize} ];
170                            }
171                            $code_ref->($input, $database, $db_config);
172                    }
173            }
174    
175    }
176    
177    
178  =head1 AUTHOR  =head1 AUTHOR
179    
180  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>

Legend:
Removed from v.682  
changed lines
  Added in v.700

  ViewVC Help
Powered by ViewVC 1.1.26