#!/usr/bin/perl -wT # specify Perl modules use strict; use CGI::Carp qw(fatalsToBrowser); # only for debugging use CGI::Carp; use CGI::Pretty qw(:all); use Time::localtime; use File::stat; # declare lexical variables my $type = 'text/html'; # HTML document type my $expires = 'now'; # browser page expiration my $css = './ybiC.css'; # Cascading Style Sheet my $title = 'CGI, CSS and Tables'; # HTML page title my $tm = localtime; # current host time my $file = '/var/www/htdocs/ybiC.cgi'; # this file my $mod = ctime(stat($file)-> mtime); # most recent modified time # generate HTML header print header( -type => "$type", -expires => "$expires", ), start_html( -style => {-src => "$css"}, -title => $title, ); # top row print table ({ bgcolor => 'orange', width => '550', align => 'center', cellspacing => '0', cellpadding => '10', border => '0' }, br, Tr ({align=> 'center', valign=> 'top'}, td({align => 'center', valign=> 'top',}, span({-class=>'big'}, ($ENV{'SERVER_NAME'})), br, span({-class=>'small'}, $ENV{'SERVER_SOFTWARE'}, br, "Perl", "$]", "   ", "$^O", "   ", $ENV{'SERVER_ADDR'}), ), # close td ), # close Tr ); # close table # Second row print table({ bgcolor => '#cc3333', width => '550', align => 'center', cellspacing => '0', cellpadding => '10', border => '0', }, Tr({align=> 'center', valign=> 'top',}, td({align => 'center', valign=> 'top',}, # most recently modified date, time span({-class=>'small'}, $tm -> mon+1, '-', $tm-> mday, '-', $tm-> year+1900, "      ", $tm-> hour, ':', $tm-> min, ':', $tm-> sec, br, 'updated', ($mod)), ), # close td ), # close Tr ); # close table # Third row print table({ bgcolor => 'green', width =>'550', align => 'center', cellspacing =>'0', cellpadding =>'10', border =>'0', }, Tr({align=> 'center', valign=> 'top',}, # Left column td({align=> 'center', valign=> 'top',}, a({href=> 'http://www.openbsd.org/'}, em('OpenBSD')), br, a({href=> 'http://www.openbsd.org/art/'}, em('OpenBSD art')), br, a({href=> 'http://www.openbsd.org/cgi-bin/man.cgi?'}, em('OpenBSD mans')), br, a({href=> 'http://www.openbsd.org/cgi-bin/man.cgi?query=afterboot&sektion=&apropos=0&m anpath=OpenBSD+Current&title=New System afterboot'}, em('OpenBSD afterboot')), br, a({href=> 'http://www.openbsd.org/security.html'}, em('OpenBSD security')), ), # close td # Right column td({ bgcolor => 'cc3333', align=> 'center', valign=> 'top',}, a({href=> 'http://www.w3.org/Style/CSS/'}, 'w3c CSS'), br, a({href=> 'http://search.cpan.org/search?dist=CSS-Parser'}, 'CSS::Parser'), br, a({href=> 'http://stein.cshl.org/WWW/software/CGI/cgi_docs.html'}, 'Stein on CGI'), br, a({href=> 'http://search.cpan.org/search?dist=CGI.pm'}, 'CGI.pm v2.70'), br, a({href=> 'http://search.cpan.org/'}, 'Search CPAN'), ), # close td ), # close Tr ); # close table # Fourth row print table ({ bgcolor => 'green', width => '550', align => 'center', cellspacing => '0', cellpadding => '10', border => '0' }, Tr ({align=> 'center', valign=> 'top'}, td({valign=> 'top'}, a({href=> 'http://www.perlmonks.org/index.pl'}, 'Monastery'), "   ", a({href=> 'http://www.perlmonks.org/index.pl?node_id=979'}, 'Fearless Leader'), "   ", a({href=> 'http://slashdot.org/'}, 'Barbarians'), ), # close td ), # close Tr ); # close table # Fifth row print table ({ bgcolor => 'gray', width => '550', align => 'center', cellspacing => '0', cellpadding => '10', border => '0' }, Tr ({align=> 'center', valign=> 'top'}, td({align => 'center', valign=> 'top',}, # remote browser & host info span({-class=>'small'}, $ENV{'REMOTE_HOST'}, "      ", $ENV{'REMOTE_ADDR'}, br, $ENV{'HTTP_USER_AGENT'}), ), # close td ), # close Tr ); # close table print end_html; =head1 NAME ybiC.cgi =head1 DESCRIPTION Simple example of CGI using CSS (Cascading Style Sheets) and HTML tables =head1 COMPATIBILITY Pass = Perl 5.006 on OpenBSD 2.7 Fail = Perl 5.00404 on Debian 2.1 (5.00404 CGI.pm has no CSS support) (CGI::Pretty not in 5.00404 std dist) Doesn't crash any browsers that I'm aware of =head1 CSS SYNTAX The following example shows just a few parameters that CSS can control. Save to file and location spec'd by $css above Blank lines are *not* allowed between sections. body { background-color: midnightblue; font-family: arial, geneva, helvetica, verdana, sans-serif; text-align: center; margin: 0px 0px 0px 0px; } A:link { text-decoration: none; font-weight: normal; line-height: 135%; color: black; } A:visited { text-decoration: none; font-weight: normal; line-height: 135%; color: black; } A:active { text-decoration: none; font-weight: normal; line-height: 135%; color: black; } A:hover { text-decoration: none; font-weight: normal; line-height: 135%; color: yellow; background-color: midnightblue; } .small { font-size: 75%; line-height: 135%; } .big { font-size: 150%; font-weight: bold; line-height: 200%; } =head1 TODO's pretty-ify file modified date - ctime(stat($file)->mtime) =head2 Constructive criticism absolutely welcome Methods for TODO's above? Any benefits to changing style from functional to OO ? =head1 SEE ALSO perldoc CGI perldoc CGI::Pretty http://search.cpan.org/search?dist=CGI.pm http://www.w3.org/Style/CSS/ http://stein.cshl.org/WWW/software/CGI/cgi_docs.html http://search.cpan.org/search?dist=CSS-Parser =head1 AUTHOR [ybiC] www.perlmonks.org =cut