# Efg.pm
#
# Easy File Generator
#
# Ralf Peine, 2004-05-26 Tue

# use strict;
# no strict refs;

package Efg;

use vars qw($version);

$version = "1.00";

use Log;
use CFG;

use Efg::Parser;
use Efg::Generator;

sub new {
    my $self = shift;

    my $type = ref($self)  ||  $self;
    my $elem = bless {}, $type; 
    $elem->init();
    return $elem;
}

sub init {
    my $self = shift;

    $self->{_parser}  = new Efg::Parser;     # Parser to read file
}

sub setParser {
    my $self = shift;

    $self->{_parser}  = shift;
}

sub addGenerator {
    my $self = shift;
    my $name = shift;
    my $gen  = shift;

    ${"GEN::$name"} = $gen;

    $gen->setParser($self->{_parser});
    $self->{_parser}->addGenerator($name);
}

# set var for the generator
sub setVar {
    # my $self    = shift;
    # my $varName = shift;
    # my $val     = shift;
    $_[0]->{_parser}->setVar(@_);
}

sub parseAndExecFile {
    my $self = shift;
    my $file = shift;

    my $perlFile = $self->{_parser}->parseFile($file);
    LOG ("==================== require $perlFile\n");
    require "$perlFile";
}

1;
