/[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 866 by dpavlin, Thu Jun 21 12:53:41 2007 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
92    
93  sub use_indexer {  sub use_indexer {
94          my $self = shift;          my $self = shift;
         my $default = 'hyperestraier';  
95          return unless ($self->{config});          return unless ($self->{config});
96          return $self->{config}->{use_indexer} || $default;          return $self->{config}->{use_indexer} || undef;
97  }  }
98    
99  =head2 get  =head2 get
# Line 117  sub webpac { Line 124  sub webpac {
124    
125          my $what = shift || return $self->{config}->{webpac};          my $what = shift || return $self->{config}->{webpac};
126    
127          if (wantarray) {          if (wantarray && ref( $self->{config}->{webpac}->{$what} ) eq 'HASH') {
128                  return keys %{ $self->{config}->{webpac}->{$what} };                  return keys %{ $self->{config}->{webpac}->{$what} };
129          } else {          } else {
130                  return $self->{config}->{webpac}->{$what};                  return $self->{config}->{webpac}->{$what};
# Line 125  sub webpac { Line 132  sub webpac {
132    
133  }  }
134    
135    =head2 iterate_inputs
136    
137      $config->iterate_inputs( sub {
138            my ($input, $database, $database_config_hash) = @_;
139            # ... do something with input config hash
140      } );
141    
142    This function will also modify C<< $input->{normalize} >> to
143    be C<ARRAY>, even with just one element.
144    
145    =cut
146    
147    sub iterate_inputs {
148            my $self = shift;
149    
150            my $log = $self->_get_logger();
151    
152            my $code_ref = shift;
153            $log->logdie("called with CODE") unless ( ref($code_ref) eq 'CODE' );
154    
155            while (my ($database, $db_config) = each %{ $self->{config}->{databases} }) {
156                    my @inputs;
157                    if (ref($db_config->{input}) eq 'ARRAY') {
158                            @inputs = @{ $db_config->{input} };
159                    } elsif ($db_config->{input}) {
160                            push @inputs, $db_config->{input};
161                    } else {
162                            $log->info("database $database doesn't have inputs defined");
163                    }
164    
165                    foreach my $input (@inputs) {
166                            $log->debug("iterating over input ", dump($input));
167                            if ( defined( $input->{normalize} ) && ref($input->{normalize}) ne 'ARRAY' ) {
168                                    $input->{normalize} = [ $input->{normalize} ];
169                            }
170                            $code_ref->($input, $database, $db_config);
171                    }
172            }
173    
174    }
175    
176    
177  =head1 AUTHOR  =head1 AUTHOR
178    
179  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>

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

  ViewVC Help
Powered by ViewVC 1.1.26