--- trunk2/lib/WebPAC.pm 2004/07/24 13:48:08 398 +++ trunk2/lib/WebPAC.pm 2004/09/09 18:08:38 418 @@ -169,6 +169,9 @@ # read database for (my $mfn = 1; $mfn <= $maxmfn; $mfn++) { + + $log->debug("mfn: $mfn\n"); + # read record my $row = OpenIsis::read( $isis_db, $mfn ); foreach my $k (keys %{$row}) { @@ -195,7 +198,7 @@ } # create lookup - my $rec = $self->{'data'}->{$mfn}; + my $rec = $self->{'data'}->{$mfn} || $log->confess("record $mfn empty?"); $self->create_lookup($rec, @{$arg->{'lookup'}}); $self->progress_bar($mfn,$maxmfn); @@ -205,6 +208,8 @@ $self->{'current_mfn'} = 1; $self->{'last_pcnt'} = 0; + $log->debug("max mfn: $maxmfn"); + # store max mfn and return it. return $self->{'max_mfn'} = $maxmfn; } @@ -268,6 +273,7 @@ printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$curr,$max,"=" x ($p/2).">", $p ); $self->{'last_pcnt'} = $p; } + print STDERR "\n" if ($p == 100); } =head2 open_import_xml @@ -329,21 +335,23 @@ $log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); foreach my $i (@_) { - if ($i->{'eval'}) { - my $eval = $self->fill_in($rec,$i->{'eval'}); - my $key = $self->fill_in($rec,$i->{'key'}); - my @val = $self->fill_in($rec,$i->{'val'}); - if ($key && @val && eval $eval) { + $log->logconfess("need key") unless defined($i->{'key'}); + $log->logconfess("need val") unless defined($i->{'val'}); + + if (defined($i->{'eval'})) { + # eval first, so we can skip fill_in for key and val + my $eval = $self->fill_in($rec,$i->{'eval'}) || next; + if ($self->_eval($eval)) { + my $key = $self->fill_in($rec,$i->{'key'}) || next; + my @val = $self->fill_in($rec,$i->{'val'}) || next; $log->debug("stored $key = ",sub { join(" | ",@val) }); push @{$self->{'lookup'}->{$key}}, @val; } } else { - my $key = $self->fill_in($rec,$i->{'key'}); - my @val = $self->fill_in($rec,$i->{'val'}); - if ($key && @val) { - $log->debug("stored $key = ",sub { join(" | ",@val) }); - push @{$self->{'lookup'}->{$key}}, @val; - } + my $key = $self->fill_in($rec,$i->{'key'}) || next; + my @val = $self->fill_in($rec,$i->{'val'}) || next; + $log->debug("stored $key = ",sub { join(" | ",@val) }); + push @{$self->{'lookup'}->{$key}}, @val; } } } @@ -775,6 +783,38 @@ return $out; } +=head2 output_file + +Create output from in-memory data structure using Template Toolkit template +to a file. + + $webpac->output_file( + file => 'out.txt', + template => 'text.tt', + data => @ds + ); + +=cut + +sub output_file { + my $self = shift; + + my $args = {@_}; + + my $log = $self->_get_logger(); + + $log->logconfess("need file name") if (! $args->{'file'}); + + $log->debug("creating file ",$args->{'file'}); + + open(my $fh, ">", $args->{'file'}) || $log->logdie("can't open output file '$self->{'file'}': $!"); + print $fh $self->output( + template => $args->{'template'}, + data => $args->{'data'}, + ) || $log->logdie("print: $!"); + close($fh) || $log->logdie("close: $!"); +} + =head2 apply_format Apply format specified in tag with C and