########################################################################
#
# $Id: MyEasyTTEmulation.pm.html,v 1.1 2002/10/12 22:09:53 gosha Exp $
#
# Copyright (c)  Okunev Igor gosha@prv.mts-nn.ru  2001-2002
#
########################################################################

package WB::Templates::MyEasyTTEmulation;

use strict;
use vars qw( @ISA @EXPORT_OK $VERSION );
use Exporter;
use Template::EasyTT;

($VERSION='$Revision: 1.1 $')=~s/^\S+\s+(\S+)\s+.*/$1/;

@ISA    = qw( Exporter );

@EXPORT_OK  = qw( process_template );

sub process_template {
    my $self = shift;
    if ( defined $self and ( ref $self eq __PACKAGE__ or UNIVERSAL::isa( $self, __PACKAGE__ ) ) ) {
        $self = shift;
    }
    my ( $file, $ptr, $output_handler ) = @_;
    
    local $_;

    unless ( defined $self->env( 'TEMPLATE' ) ) {
        unless ( defined $self->env( 'TEMPLATE' => Template::EasyTT->new( {
                    INCLUDE_PATH=> $self->cfg( 'HOME_DIR' ),
                    PARENT      => $self,

                    SECURE_INC  => 0,

                    LOCK_OK     => 1,

                    GLOBAL_IF   => 1,
                    LOCAL_IF    => 1,

                    INCLUDE     => 1,
                    FOREACH     => 1,

                    FILTERS     => $self->add_filter
                } ) ) ) {

            $self->log_error( $Template::EasyTT::ERROR );
            $self->print("Internal ERROR [".__LINE__."]\n");
            return 0;
        }
    }

    if ( defined $output_handler ) {
        unless ( $self->env( 'TEMPLATE' )->process( $file, $ptr, $output_handler ) ) {
            $self->log_error( $Template::EasyTT::ERROR );
            return 0;
        }
    } else {
        unless ( $self->env( 'TEMPLATE' )->process( $file, $ptr, $self ) ) {
            $self->log_error( $Template::EasyTT::ERROR );
            return 0;
        }
    }

    return 1;
}

1;