#!/usr/local/bin/perl
use strict;
use XML::XPath;

my $file = \*DATA;
my $xp = XML::XPath -> new( ioref => $file );
my $xmltext = $xp -> findvalue( '/doc/text()' );

use Template;
my $tt = Template->new( { INCLUDE_PATH => "." } );


my $template;

print "--- through tt INSERT ---\n";

$template = 
qq!xml var text: [% xmltext %]
    template: [% INSERT footer %]
!;

$tt -> process( \$template, { xmltext => $xmltext } ) 
  or die "Error: ", $tt->error();


print "--- through tt PROCESS ---\n";

$template = 
qq!xml var text: [% xmltext %]
    template: [% PROCESS footer %]
!;

$tt -> process( \$template, { xmltext => $xmltext } ) 
  or die "Error: ", $tt->error();


print "--- through tt INCLUDE ---\n";

$template = 
qq!xml var text: [% xmltext %]
    template: [% INCLUDE footer %]
!;

$tt -> process( \$template, { xmltext => $xmltext } ) 
  or die "Error: ", $tt->error();


my $footer;

print "--- manually without pack/unpack 'U*' ---\n";

open FH, 'footer';
$footer = join( '', <FH> );
close FH;

print 
qq!xml var text: $xmltext
    template: $footer
!;


print "--- manually with pack/unpack 'U*' ---\n";

open FH, 'footer';
$footer = join( '', <FH> );
close FH;

$footer = pack('U*', unpack('U*', $footer ) );

print 
qq!xml var text: $xmltext
    template: $footer
!;


print "--- the end ---\n";

__DATA__
<?xml version='1.0' encoding='utf-8'?>
<doc>привет</doc>
