--- trunk2/lib/WebPac.pm 2004/06/15 22:40:07 352 +++ trunk2/lib/WebPac.pm 2004/06/16 11:29:37 353 @@ -1,6 +1,8 @@ package WebPac; use Carp; +use Text::Iconv; +use Config::IniFiles; =head1 NAME @@ -8,7 +10,7 @@ =head1 DESCRIPTION -This class does basic thing for WebPac. +This module implements methods used by WebPac. =head1 METHODS @@ -23,6 +25,11 @@ Default C is C. +It will also read configuration files +C (used by indexer and Web font-end) +and configuration file specified by C +which describes databases to be indexed. + =cut sub new { @@ -34,17 +41,9 @@ # output codepage $self->{'code_page'} = 'ISO-8859-2' if (! $self->{'code_page'}); - return $self; -} - -=head2 read_global_config - -Read global configuration (used by indexer and Web font-end) - -=cut - -sub read_global_config { - my $self = shift; + # + # read global.conf + # $self->{global_config_file} = new Config::IniFiles( -file => 'global.conf' ) || croak "can't open 'global.conf'"; @@ -60,17 +59,9 @@ $self->{global_config}->{$var} = $self->{global_config_file}->val('global', $var); } - return $self; -} - -=head2 read_indexer_config - -Read indexer configuration (specify databases, types etc.) - -=cut - -sub read_indexer_config { - my $self = shift; + # + # read indexer config file + # $self->{indexer_config_file} = new Config::IniFiles( -file => $self->{config_file} ) || croak "can't open '$self->{config_file}'"; @@ -102,8 +93,8 @@ By default, ISIS code page is assumed to be C<852>. -If C is set, it will read just 500 records from -database in example above. +If optional parametar C is set, it will read just 500 records +from database in example above. Returns number of last record read into memory (size of database, really). @@ -127,6 +118,8 @@ croak "need filename" if (! $arg->{'filename'}); my $code_page = $arg->{'code_page'} || '852'; + use OpenIsis; + #$self->{'isis_code_page'} = $code_page; # create Text::Iconv object @@ -196,7 +189,14 @@ $webpac->fill_in($rec,'v250^a'); Optional argument is ordinal number for repeatable fields. By default, -it's assume to be first repeatable field. +it's assume to be first repeatable field (fields are perl array, so first +element is 0). +Following example will read second value from repeatable field. + + $webpac->fill_in($rec,'Title: v250^a',1); + +This function B perform parsing of format to inteligenty skip +delimiters before fields which aren't used. =cut @@ -209,7 +209,7 @@ my $i = shift || 0; # FIXME remove for speedup? - if ($rec !~ /HASH/) { + if ($rec !~ /HASH/o) { confess("need HASH as first argument!"); } @@ -241,8 +241,13 @@ $format =~ s/v(\d+)\^(\w)/get_sf(\$found,\$rec,$1,$2,$i)/ges; $format =~ s/v(\d+)/get_nosf(\$found,\$rec,$1,$i)/ges; - if ($found) { - return $format; + if ($found) { + # do we have lookups? + if ($format =~ /\[[^\[\]]+\]/o) { + return $self->lookup($format); + } else { + return $format; + } } else { return; } @@ -261,27 +266,27 @@ my $tmp = shift || confess "need format"; - if ($tmp =~ /\[[^\[\]]+\]/) { + if ($tmp =~ /\[[^\[\]]+\]/o) { my @in = ( $tmp ); -print "##lookup $tmp\n"; +#print "##lookup $tmp\n"; my @out; while (my $f = shift @in) { if ($f =~ /\[([^\[\]]+)\]/) { my $k = $1; if ($self->{'lookup'}->{$k}) { -print "## lookup key = $k\n"; +#print "## lookup key = $k\n"; foreach my $nv (@{$self->{'lookup'}->{$k}}) { my $tmp2 = $f; $tmp2 =~ s/\[$k\]/$nv/g; push @in, $tmp2; -print "## lookup in => $tmp2\n"; +#print "## lookup in => $tmp2\n"; } } else { undef $f; } } elsif ($f) { push @out, $f; -print "## lookup out => $f\n"; +#print "## lookup out => $f\n"; } } return @out;