# Acts as a register bank for page creation tools 
# Users should set tag paramaters eg-"onload" w/out <, >, or tag name

package Page;
require Exporter;

our @ISA  = qw(Exporter);
our @EXPORT= qw( new setHead setTitle setScript setBody createPage showHead showTitle showScript showBody );

sub new{

    my $invocant = shift;
    my $class    = ref($invocant) || $invocant;

    $page= {
	head   => {start=>"", content=>"", end=>"" },
	script => {start=>"", content=>"", end=>"" },
	title  => {start=>"", content=>"", end=>"" },
	body   => {start=>"", content=>"", end=>"" }
    };

    bless($page, $class);
    return $page;
}


# FUNCTIONS FOR VIEWING CONTENT

sub showHead{
    my $self = shift;
    print $self{head}{content};
}

sub showTitle{
    my $self = shift;
    print $self{title}{content};
}

sub showScript{
    my $self = shift;
    print $self{script}{content};
}

sub showBody{
    my $self = shift;
    print $self{body}{content};
}


# FUNCTIONS FOR SETTING VARS

#Append head
sub setHead{
    my $self = shift;
    $self{head}{content}   .= shift;
}

#Replaces title
sub setTitle{
    my $self = shift;
    $self{title}{content}  .=  shift;
}

#Appends script
sub setScript{
    my $self = shift;
    $self{script}{content} .= shift;
}

#Appends body
sub setBody{
    my $self = shift;
    $self{body}{content}   .= shift;
}


#FUNCTIONS FOR SETTING TAGS

sub setTitleTag{
    my $self = shift;
    $self{title}{start}  .= " " . shift;
}

sub setScriptTag{
    my $self = shift;
    $self{script}{start} .= " " . shift;
}

sub setBodyTag{
    my $self = shift;
    $self{body}{start}   .= " " . shift;
}

#create starttags... append contents/// append endtag
sub prepHTML(){

    my $self = shift;

   # STARTTAG-- take whatever is in each starttag and add appropriate
	#tag name along with brackets <>   

    $self{head}{start}   = "<head "   . $self{head}{start}   . " > \n";
    $self{title}{start}  = "<title "  . $self{title}{start}  . " >"   ;
    $self{script}{start} = "<script " . $self{script}{start} . " > \n";
    $self{body}{start}   = 
	"<body text='e5eeee' link='e5eeee' vlink='e5eeee' alink='e5eeee' " . 
	 $self{body}{start}   . " > \n";

   # CONTENTS-- no action

    #ENDTAG  -- set to <TAGNAME>
    $self{head}{end}   = "</head>   \n";
    $self{title}{end}  = "</title>  \n";
    $self{script}{end} = "</script> \n";
    $self{body}{end}   = "</body>   \n";

    # CONCAT TAGS AND CONTENT TO page{#####}{contents}

    $self{title}{content}  = $self{title}{start}  . $self{title}{content}  . $self{title}{end};

    $self{script}{content} = $self{script}{start} . $self{script}{content} . $self{script}{end};

    $self{head}{content} = 
	$self{head}{start}     . 
	$self{title}{content}  .
	$self{head}{content}   . 
	$self{script}{content} .
	$self{head}{end}       ;

    $self{body}{content}   = $self{body}{start}   . $self{body}{content}   . $self{body}{end};

    return $self;
}


#append ALL 
#returns scaler
sub createPage(){

    my $self = shift;
    
    $self = $self->prepHTML;


    $HTML= "<html>                  \n";

    $HTML .=$self{head}{content} . "\n";
    $HTML .=$self{body}{content} . "\n";

    $HTML .= "</html>               \n";
 
    return $HTML;
}
#END FILE

