--- trunk2/lib/WebPAC.pm 2004/06/17 12:27:02 368 +++ trunk2/lib/WebPAC.pm 2004/06/17 17:25:12 370 @@ -7,6 +7,7 @@ use Text::Iconv; use Config::IniFiles; use XML::Simple; +use Template; use Data::Dumper; @@ -60,7 +61,7 @@ # read global.conf # - $self->{global_config_file} = new Config::IniFiles( -file => 'global.conf' ) || croak "can't open 'global.conf'"; + my $config = new Config::IniFiles( -file => 'global.conf' ) || croak "can't open 'global.conf'"; # read global config parametars foreach my $var (qw( @@ -70,8 +71,9 @@ dbi_passwd show_progress my_unac_filter + output_template )) { - $self->{global_config}->{$var} = $self->{global_config_file}->val('global', $var); + $self->{'global_config'}->{$var} = $config->val('global', $var); } # @@ -80,7 +82,18 @@ $self->{indexer_config_file} = new Config::IniFiles( -file => $self->{config_file} ) || croak "can't open '$self->{config_file}'"; + # create UTF-8 convertor for import_xml files $self->{'utf2cp'} = Text::Iconv->new('UTF-8' ,$self->{'code_page'}); + + # create Template toolkit instance + $self->{'tt'} = Template->new( + INCLUDE_PATH => ($self->{'global_config_file'}->{'output_template'} || './output_template'), +# FILTERS => { +# 'foo' => \&foo_filter, +# }, + EVAL_PERL => 1, + ); + return $self; } @@ -232,8 +245,6 @@ ForceContent => 1 ); - print Dumper($self->{'import_xml'}); - } =head2 create_lookup @@ -568,8 +579,35 @@ } - print "data_structure => ",Dumper(\@ds); + return @ds; + +} + +=head2 output + +Create output from in-memory data structure using Template Toolkit template. + +my $text = $webpac->output( template => 'text.tt', data => @ds ); +=cut + +sub output { + my $self = shift; + + my $args = {@_}; + + confess("need template name") if (! $args->{'template'}); + confess("need data array") if (! $args->{'data'}); + + my $out; + + $self->{'tt'}->process( + $args->{'template'}, + $args, + \$out + ) || confess $self->{'tt'}->error(); + + return $out; } 1;