Omri's Perl Adventures

FAQ
* Perl stuff
Mason stuff
Tk stuff
RecDescent
stuff
C stuff
Randomness
Punditry
Links

First off, here's the Perl script I use to create my Web pages. I use HTML::Mason, and this script is what you use to generate static content with it:

#!/usr/bin/perl 
use HTML::Mason; 	
use Getopt::Std; 
getopts('o:i:'); 	
my $outbuf;
if (!$opt_o) { 
    $opt_o = $opt_i; 
}
my $parser = new HTML::Mason::Parser;
my $interp = new HTML::Mason::Interp (parser=>$parser,
				      comp_root=>"$ENV{HOME}/www/components",
				      data_dir=>"/tmp/",
				      out_method=>\$outbuf);
$comp = $parser->make_component
    (script_file => "$ENV{HOME}/www/components/$opt_i") ;

my $retval = $interp->exec($comp);
open(F,">$ENV{HOME}/www/$opt_o");
print F $outbuf;
close(F);
print "return value of component was: $retval\n";
This is the simplest Mason handler you can make.

Having that, you can make simple header and footer components. Here's a header component.

<%perl>
if ($heading) { 
        $heading = '<h1>' . $heading . "</h1>\n" ; 
} else { 
        $heading = '<h1>' . $title . "</h1>\n" ; 
}
</%perl>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">
    
<HTML>

 <HEAD>
 <TITLE><% $title %> </TITLE>
 </HEAD>

 <BODY BGCOLOR = "<% $bgcolor %>"
       TEXT    = "<% $txcolor %>" 
       VLINK   = "<% $vlcolor %>" 
       LINK    = "<% $lncolor %>" >
<% $heading %> 
This would almost be enough, except we need to describe the arguments we're using. More on that later. Back to the component:
<table width="99%"  cellpadding=0 cellspacing=0 align=top
  border=0 bgcolor="<% $bgcolor %>" >

<tr valign="top" align="left">

<td bgcolor="<% $sidebar_bg %>"

 valign=top > 

<table height="100%" width="99%" align="left" cellpadding=0 cellspacing=0
  border=0 ><TR>
<td align="left">
<font   color="<% $sidebar_fg %>" >
<a href="faq.html">faq</a><br>
<a href="perl.html">perlstuff</a><br>
<a href="cstuff.html"> C stuff</a><br>
<a href="randomness.html">randomness</a><br>
</font>
</td>

</tr>
</table>

</td>
<td>
Now we've created our table for a sidebar to the left. With all that done, we can define our input arguments and be done. Arguments without a default are required to be specified by the Mason component that calls this one:
<%args>

        $title
        $sidebar_bg => "#22bb22"
        $sidebar_fg => "#ff0000"
        $sidebar_subtopic => ''
        $heading => ''
        $bgcolor =>  "#006600"
        $txcolor =>  "#FFFFFF"
        $vlcolor =>  "#999999" 
        $lncolor =>  "#FFFFFF" 
</%args>
So, to generate this web page, we put in a header call at the top:
<& headers.comp, title => 'Omri\'s Perl Adventures' &>
I hope you liked my little Mason tutorial. My components are stored in this directory. If you use them, how's this for a trade: my graphics skills leave a bit to be desired. You give me some Web-usefull PNG's in return for my Mason components. Please? Pretty please?
Home To top

Omri Schwarz, March 9, 2001