#!/usr/bin/perl
#
#  Compile and/or show compiled version of WebDyne HTML scripts
#
package main;


#  Compiler pragma, load library path
#
use strict qw(vars);
use vars   qw($VERSION $REVISION);
use FindBin qw($RealBin);
use lib $RealBin;
use File::Spec;
use perl5lib File::Spec->catdir($RealBin, File::Spec->updir());


#  Use the base and constants module
#
use WebMod::Base qw(:all);


#  External modules
#
use WebDyne::Compile;
use Getopt::Long;
use Data::Dumper;
use CGI;


#  Version Info, must be all one line for MakeMaker, CPAN.
#
$VERSION = eval { require WebDyne::VERSION; do $INC{'WebDyne/VERSION.pm'}};


#  Release info
#
$REVISION = (qw $Revision: 1.8 $)[1];


#  Run main
#
&main(\@ARGV) || die errdump();


#============================================================================


sub main {


    #  Get argv array ref
    #
    my $argv_ar=shift();


    #  Base options will pass to compile
    #
    my %option=(

	nofilter    =>	1,  #don't run through any filters
	noperl	    =>  1,  #don't run perl code,
	stage4	    =>  1,

       );


    #  Now import command line options
    #
    GetOptions(\%option, 'stage0|0', 'stage1|1', 'stage2|2', 'stage3|3', 'meta');


    #  Get srce file, add to options
    #
    my $srce_fn=$argv_ar->[0] ||
	return err('no source file specified');
    $option{'srce'}=$srce_fn;


    #  Create and run compile object
    #
    my $compile_or=WebDyne::Compile->new();
    my $data_ar=$compile_or->compile(\%option) ||
	return err();


    #  Dump it
    #
    $Data::Dumper::Indent=1;
    print Data::Dumper::Dumper(grep {$_} $option{'meta'} ? $data_ar->[0] : undef, $data_ar->[1]);


}

