Используя модуль CGI, дополните пример
Упражнения
1. Запишите текст примера 15.8 в обозначениях, использующих объектно-ориентированный интерфейс с модулем CGI.
2. Используя модуль CGI, дополните пример 15.8 кодом, осуществляющим проверку введенных данных, как это сделано в примере 15.76.
3. Ниже приведены тексты трех примеров, входящих в отдельный дистрибутив модуля CGI.pm. Разберите, что делают эти сценарии.
a) clickable_image.cgi
#!/usr/bin/perl
use CGI;
$query = new CGI;
print $query->header;
print $query->start__html("A Clickable Image");
print «END;
<H1>A Clickable Image</H1>
</A> /
END |
print "Sorry, this isn't very exciting!\n";
print $query->startform;
print $query->image_button('picture',"./wilogo.gif"); print "Give me a: ", $query->popup_rnenu ('letter',
['A', 'B', 'C', 'D', 'E', 'W]),"\n"; print "<P>Magnification: ", $query->radio_group('magnification',
['IX' ,'2X',MX','20X']),"\n"; print "<HR>\n"; if ($query->param) {
print "<P>Magnification, <EM>",$query->param('magnification'),
"</EM>\n";
print "<P>Selected Letter, <EM>",$query->param( 'letter'),"</EM>\n"; ($x,$y) = ($query->param('picture.x'),$query->param('picture.y')) ; print "<P>Selected Position <EM>($x,$y)</EM>\n";
}
print $query->end_html;
6) quadraphobia.cgi #!/usr/bin/perl use CGI qw/:standard/; print header,
start_html('QuadraPhobia'),
hi('QuadraPhobia'),
start_form(),
image_button(-name=>'square',
-src=>'red_square.gif,
-width=>200,
-height=>200,
-align=>MIDDLE),
end_form(); if (paramO) {
($x,$y) = (param('square.x'),param('square.у'));
$pos = 'top-left' if $x < 100 && $y < 100;
$pos = 'top-right' if $x >= 100 && $y < 100;
$pos = 'bottom-left' if $x < 100 && $y >= 100;
$pos = 'bottom-right' if $x >= 100 && $y >= 100;
print b(" You clicked on the $pos part of the square."); }
print p,a({href=>'../source.html'},"Code examples"); print end_html ();
в) popup.cgi
#!/usr/local/bin/perl
use CGI;
$query = new CGI;
print $query->header;
print $query->start_html('Popup Window');
if (!$query->param) {
print "<Hl>Ask your Question</Hl>\n";
print $query->startform(-target=>'_new');
print "What's your name? ",$query->textfield('name'); .
print "<P>What's the corobination?<P>",
$query->checkbox_group(-name=>'words',
-values=>['eenie','meenie','minie','moe'],
-defaults=>['eenie','moe']);
print "<P>What's your favorite color? ", $query->popup_menu(-name=>'color',
-values=>['red','green','blue','chartreuse']), "<P>";
print $query->submit; print $query->endform;
} else {
print "<H1>And the Answer is...</H1>\n";
print "Your name is <EM>",$query->param(name),"</EM>\n";
print "<P>The keywords are: <EM>",
join(", ",$query->param(words)),"</EM>\n"; print "<P>Your favorite color is <EM>",
$query->param{color),"</EM>\n";
}
print qq{<P><A HREF="cgi_docs.html">Go to the documentation</A>};
print $query->end_html;