#!/usr/bin/perl -w

use strict;
use HTML::Template;

my $ver = $HTML::Template::VERSION;

unless ($ver eq '2.5' || $ver eq '2.6') {
    die "test can be run for HTML::Template Version 2.5 or 2.6 only\n";
}

my $tmpl_path = '/tmp/__html_template_test___';
mkdir $tmpl_path;
chdir $tmpl_path;
my $dir = 'DIR';
mkdir $dir;
my $outer_file = "$dir/outer.tpl";
my $top_nested_file = 'top_nested.tpl';
my $top_nested_file_2 = 'top_nested_2.tpl';
my $inside_nested_file = "inside_nested.tpl";

open (OUT, "> $outer_file") || die "unable to open $outer_file : $!\n";
print OUT <<EOF;
    <TMPL_INCLUDE NAME="$top_nested_file"> <!-- implicitly got from : <$tmpl_path> -->
    <TMPL_INCLUDE NAME="$inside_nested_file"> <!-- implicitly got from : <$dir> -->
EOF
close OUT;

open (TOP, "> $top_nested_file") || die "unable to open $top_nested_file : $!\n";
print TOP <<EOF;
   Test top level nested File 1
    <TMPL_INCLUDE NAME="$top_nested_file_2"> <!-- implicitly got from : <$tmpl_path> -->
EOF
close TOP;

open (TOP2, "> $top_nested_file_2") || die "unable to open $top_nested_file_2 : $!\n";
print TOP2 <<EOF;
   Test top level nested File 2
EOF
close TOP2;

open (INNER, "> $dir/$inside_nested_file") || die "unable to open $dir/$inside_nested_file : $!\n";
print INNER <<EOF;
   Inside nested File
EOF
close INNER;

my $tmpl = HTML::Template->new(filename => $outer_file, path => $tmpl_path);

END {
    print "\n## ALERT ####### \n";
    print "## Directory <$tmpl_path> was created for this test.\n";
    print "## Please remove it manually\n";
    print "## ALERT ####### \n";
}
