Friday, November 18, 2005

jartur::Perl 6.My First OOP CGI Script


#!/usr/bin/pugs

# LFDC
# 2005-11-18

use v6;

class CGI
{
has $:header;
# This class has one private field or property.
# $.a means public when $:a means private field.
# When using $.a if you want to make it writeable you should write: has $.a is rw

method setHeader ( $content_type, $charset )
{
$:header = "Content-type:" ~ $content_type ~ "; charset=" ~ $charset ~ "\n\n";
}

method printHeader
{
print $:header;
}

method testSquares
{
print "<html>\n<head>\n<title>Perl6(!) CGI OOP</title>\n</head>\n";
print "<body>\n";
print "<table align=\"center\" width=\"0px\">\n";

my $tr_counter;
my $td_counter;

loop $tr_counter = 0; $tr_counter <= 100; $tr_counter++
{
print "<tr>\n";

loop $td_counter = 0; $td_counter <= 10; $td_counter++
{
print "<td style=\"background-color:" ~ $tr_counter ~ $td_counter ~ $tr_counter ~ "\" width=\"1px\" height=\"1px\">";
print "</td>\n";
}

print "</tr>\n";
}

print "</table>\n";
print "</body>\n</html>\n";

}
}

my $CGIObject = CGI.new;
$CGIObject.setHeader( "text/html", "utf-8" );
$CGIObject.printHeader;
$CGIObject.testSquares;

0 Comments:

Post a Comment

<< Home