<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># -------------------------------------------------------------------------------------
# lib::Template::Include
# -------------------------------------------------------------------------------------
#
#    Author   : Jean-Michel Hiver                         (c) Jean-Michel Hiver, 2001.
#    Synopsis : Provides the implementation for the
#               &lt;% include ... %&gt; tag.
#
# -------------------------------------------------------------------------------------
package lib::Template::Include;
use lib::Template::AbstractTag;
use lib::Exception;
use lib::Template;
use strict;
use vars qw /$DECIMAL_TO_HTML @ISA/;
@ISA = qw /lib::Template::AbstractTag/;


##
# $obj-&gt;main;
# -----------
#   Includes "something" (it can be a file, a file given by a variable, or
#   a variable itself) in the current template.
#
#   &lt;% include file="myvariable" [from_variable="1"] [reparse="0"] %&gt;
#   &lt;% include data="my_variable_data" [reparse="0"] %&gt;
##
sub main
{
    my $self   = shift;
    my $result = $self-&gt;result;
    my $tokens = $self-&gt;tokens;    
    my ($token_name, $token_info) = $self-&gt;parse_tag (shift @{$tokens});

    my $data;

    # &lt;% include file="myfile.tmpl" %&gt;
    # &lt;% include file="myvariable" from_variable="1" %&gt;
    if (defined $token_info-&gt;{file})
    {
	my $file;
	if (defined $token_info-&gt;{from_variable} and $token_info-&gt;{from_variable})
	{
	    $file = $self-&gt;get ($token_info-&gt;{file});
	}
	else
	{
	    $file = $token_info-&gt;{file};
	}

	$file = $self-&gt;get_filepath ($file);
	open FP, "&lt;$file" or
	    throw (new lib::Exception ( code =&gt; 'CANNOT_OPEN_FILE',
					info =&gt; $self ) );
	$data = join '', &lt;FP&gt;;
	close FP;
    }

    # &lt;% include data="my_variable_data" %&gt;
    elsif (defined $token_info-&gt;{data})
    {
	$data = $self-&gt;get ($token_info-&gt;{file});
    }
    else
    {
	throw (new lib::Exception ( code =&gt; 'UNVALID_INCLUDE_TAG',
				    info =&gt; $self ) );
    }

    # &lt;% include ... reparse="1" %&gt; (default)
    # &lt;% include ... reparse="0" %&gt; (does not re-parse the included file)
    $token_info-&gt;{reparse} = 1 unless (exists $token_info-&gt;{reparse});
    if ($token_info-&gt;{reparse})
    {
	my $tmpl = $self-&gt;{class}-&gt;new ( data =&gt; $data, hash =&gt; $self-&gt;{hash} );
	push @{$result}, $tmpl-&gt;parse;
    }
    else
    {
	push (@{$result}, $data);
    }
}


sub get_filepath
{
    my $self = shift;
    return shift;
}


1;

</pre></body></html>