268 |
printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$curr,$max,"=" x ($p/2).">", $p ); |
printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$curr,$max,"=" x ($p/2).">", $p ); |
269 |
$self->{'last_pcnt'} = $p; |
$self->{'last_pcnt'} = $p; |
270 |
} |
} |
271 |
|
print STDERR "\n" if ($p == 100); |
272 |
} |
} |
273 |
|
|
274 |
=head2 open_import_xml |
=head2 open_import_xml |
657 |
my @ds = $webpac->data_structure($rec); |
my @ds = $webpac->data_structure($rec); |
658 |
|
|
659 |
This method will also set C<$webpac->{'currnet_filename'}> if there is |
This method will also set C<$webpac->{'currnet_filename'}> if there is |
660 |
<filename> tag in C<import_xml>. |
<filename> tag in C<import_xml> and C<$webpac->{'headline'}> if there is |
661 |
|
<headline> tag. |
662 |
|
|
663 |
=cut |
=cut |
664 |
|
|
671 |
$log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); |
$log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); |
672 |
|
|
673 |
undef $self->{'currnet_filename'}; |
undef $self->{'currnet_filename'}; |
674 |
|
undef $self->{'headline'}; |
675 |
|
|
676 |
my @sorted_tags; |
my @sorted_tags; |
677 |
if ($self->{tags_by_order}) { |
if ($self->{tags_by_order}) { |
709 |
@v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v; |
@v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v; |
710 |
} |
} |
711 |
|
|
712 |
|
if ($field eq 'filename') { |
713 |
|
$self->{'current_filename'} = join('',@v); |
714 |
|
$log->debug("filename: ",$self->{'current_filename'}); |
715 |
|
} elsif ($field eq 'headline') { |
716 |
|
$self->{'headline'} .= join('',@v); |
717 |
|
$log->debug("headline: ",$self->{'headline'}); |
718 |
|
next; # don't return headline in data_structure! |
719 |
|
} |
720 |
|
|
721 |
# does tag have type? |
# does tag have type? |
722 |
if ($tag->{'type'}) { |
if ($tag->{'type'}) { |
723 |
push @{$row->{$tag->{'type'}}}, @v; |
push @{$row->{$tag->{'type'}}}, @v; |
726 |
push @{$row->{'swish'}}, @v; |
push @{$row->{'swish'}}, @v; |
727 |
} |
} |
728 |
|
|
|
if ($field eq 'filename') { |
|
|
$self->{'current_filename'} = join('',@v); |
|
|
$log->debug("filename: ",$self->{'current_filename'}); |
|
|
} |
|
729 |
|
|
730 |
} |
} |
731 |
|
|
776 |
return $out; |
return $out; |
777 |
} |
} |
778 |
|
|
779 |
|
=head2 output_file |
780 |
|
|
781 |
|
Create output from in-memory data structure using Template Toolkit template |
782 |
|
to a file. |
783 |
|
|
784 |
|
$webpac->output_file( |
785 |
|
file => 'out.txt', |
786 |
|
template => 'text.tt', |
787 |
|
data => @ds |
788 |
|
); |
789 |
|
|
790 |
|
=cut |
791 |
|
|
792 |
|
sub output_file { |
793 |
|
my $self = shift; |
794 |
|
|
795 |
|
my $args = {@_}; |
796 |
|
|
797 |
|
my $log = $self->_get_logger(); |
798 |
|
|
799 |
|
$log->logconfess("need file name") if (! $args->{'file'}); |
800 |
|
|
801 |
|
$log->debug("creating file ",$args->{'file'}); |
802 |
|
|
803 |
|
open(my $fh, ">", $args->{'file'}) || $log->logdie("can't open output file '$self->{'file'}': $!"); |
804 |
|
print $fh $self->output( |
805 |
|
template => $args->{'template'}, |
806 |
|
data => $args->{'data'}, |
807 |
|
) || $log->logdie("print: $!"); |
808 |
|
close($fh) || $log->logdie("close: $!"); |
809 |
|
} |
810 |
|
|
811 |
=head2 apply_format |
=head2 apply_format |
812 |
|
|
813 |
Apply format specified in tag with C<format_name="name"> and |
Apply format specified in tag with C<format_name="name"> and |