--- trunk2/lib/WebPAC.pm 2004/07/20 17:15:48 389 +++ trunk2/lib/WebPAC.pm 2004/09/07 18:01:36 412 @@ -268,6 +268,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 @@ -656,7 +657,8 @@ my @ds = $webpac->data_structure($rec); This method will also set C<$webpac->{'currnet_filename'}> if there is - tag in C. + tag in C and C<$webpac->{'headline'}> if there is + tag. =cut @@ -669,6 +671,7 @@ $log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); undef $self->{'currnet_filename'}; + undef $self->{'headline'}; my @sorted_tags; if ($self->{tags_by_order}) { @@ -706,6 +709,15 @@ @v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v; } + if ($field eq 'filename') { + $self->{'current_filename'} = join('',@v); + $log->debug("filename: ",$self->{'current_filename'}); + } elsif ($field eq 'headline') { + $self->{'headline'} .= join('',@v); + $log->debug("headline: ",$self->{'headline'}); + next; # don't return headline in data_structure! + } + # does tag have type? if ($tag->{'type'}) { push @{$row->{$tag->{'type'}}}, @v; @@ -714,10 +726,6 @@ push @{$row->{'swish'}}, @v; } - if ($field eq 'filename') { - $self->{'current_filename'} = join('',@v); - $log->debug("filename: ",$self->{'current_filename'}); - } } @@ -768,6 +776,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