| Category: | CGI |
| Author/Contact Info | ybiC |
| Description: | ## deprecated by (code) Toy Template ##
A simple script that uses CGI::Pretty to create an HTML document with CSS (Cascading Style Sheet) and tables.
Also includes stupid pet tricks like presenting server info and client info in generated page.
Constructive criticism absolutely welcome.
Update: Thanks to zdog, davorg, and tye for pointing out redundancy of creating package variables and lexical variables with same names, and for insight into applications of each. Update 2: Changed "background:" to "background-color:" in CSS section A:hover so all CSS1 browsers display properly. |
#!/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?quer
+y=afterboot&sektion=&apropos=0&m anpath=OpenBSD+Current&title=New Sys
+tem 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-Pars
+er'}, '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'}, " &n
+bsp;",
$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 tabl
+es
=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 contro
+l.
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
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(zdog) RE: CGI.pm for CSS, tables, pet tricks
by zdog (Priest) on Aug 13, 2000 at 10:41 UTC | |
by davorg (Chancellor) on Aug 14, 2000 at 17:52 UTC | |
by ybiC (Prior) on Aug 14, 2000 at 19:27 UTC | |
by davorg (Chancellor) on Aug 14, 2000 at 19:31 UTC | |
by tye (Sage) on Aug 14, 2000 at 19:52 UTC | |
|
RE: CGI.pm for CSS, tables, pet tricks
by Maclir (Curate) on Aug 14, 2000 at 02:36 UTC |