Re: libwww-perl-5b5 released

Chris Fedde (cfedde@loupe.ezsrc.mrg.uswest.com)
Sun, 01 Oct 1995 18:42:59 -0600


In message <199509290902.KAA07255@bergen.oslonett.no>you write:
>Chris Fedde writes:
>> ! # Elements that do not have corresponding end tags
>>   for (qw(base link meta isindex nextid
>>   	img br hr wbr
>> + 	th tr td
>> + 	dt dd li
>>   	input
>>          )
>>       ) {
>>       $noEndTag{$_} = 1;
>>   }
>
>This is wrong!
>
>The th tr td dt dd and li tags are not like the other tags in this list, 
>because the corresponding elements are containers.  The hash should really be 
>called %emptyElements or something like that.
>
>--Gisle
>

Gisle,

My goal with this patch was to get the correct behavior for tables
and lists.  With out this patch the th, tr, td, dd, dt, dd, li
(also option) element types generate unwanted end tags.  Perhaps
I was mislead by the comment but the behavior that I desired was
acheved through this patch.

Find below a short example of what I'm doing.
chris
--
#!/usr/bin/perl
#
# calendar.cgi
#
# process a month and year into a calendar
# Uses cal(1)
#

use CGI::Request;
use English;
use Carp;

require HTML::Element;

package Calendar;

$calid = "calendar0000";

sub new
{
    my ($type, $day, $month, $year, $callback) = @_;
    my @calendar;
    my $cal;
    my $self = {};

    open(C, "cal $month $year|") 
	or &croak("can't open calendar for $month $year\n");

    @calendar = <C>;
    close<C>;

    chomp($calendar[0]);

    $self->{Caption} = $calendar[0];

    $cal = new HTML::Element 'Table', Border=>1, ID=>$calid;

    $caption = new HTML::Element Caption;
    pushContent $caption $self->{Caption};
    pushContent $cal $caption;

    # day of week line
    pushContent $cal (new HTML::Element 'Tr');
    for (qw ( Sun Mon Tue Wed Thu Fri Sat ))
    {
	pushContent $cal (new HTML::Element 'Th');
	pushContent $cal $_;
    } 

    # fill in days
    for (2..$#calendar)
    {
	pushContent $cal (new HTML::Element 'Tr');
	for ($calendar[$_] =~ m/(..).?/g)
	{
	    pushContent $cal (new HTML::Element 'Td');
	    pushContent $cal (&$callback($_, $month, $year)) if ($_ =~ /\d+/);
	} 
    }

    $self->{HTML} = $cal;
    bless $self;
}

sub caption
{
    my $self = shift;

    $self->{Caption};
} 

sub html
{
    my $self = shift;

    $self->{HTML};
} 

package main;

%Month = ( January => 1, February => 2, March => 3,
	   April => 4, May => 5, June => 6,
	   July => 7, August => 8, September => 9,
	   October => 10, November => 11, December => 12 );

@Month = qw( January February March April May June
	     July August September October  November December );

$req = new CGI::Request;

print "Content-Type: text/html\n\n";

#
# get the curent date
#
($this_day, $this_month, $this_year) = (localtime(time))[3, 4,5];

$this_month++;
$this_year += 1900;

#
# reset $this_month if it's available in CGI param
#
if (param $req "month")
{
    $this_month = $Month{param $req "month"};
    $this_day = 0;
}

#
# generate the date selection form
#
$form = new HTML::Element 'Form', Action=>"calendar.cgi", Method=>Post;
$month_popup = new HTML::Element 'select', Name=>"month";
for (@Month)
{
    my $option = new HTML::Element 'option';
    attr $option Selected => 1 if ($Month{$_} == $this_month);
    pushContent $month_popup $option, $_;
} 
pushContent $form $month_popup, new HTML::Element 'Input', Type=>Submit;

#
# Set Up the Document
#
$doc  =  new HTML::Element 'html';

#
# Create the primary content
$calendar = new Calendar $this_day, $this_month, $this_year, \&cellfor;

# set up the Document Head
#
$head =  new HTML::Element 'head';
$title = new HTML::Element 'Title';
pushContent $title $calendar->caption;
pushContent $head  $title;

#
#  And set up the body
#
$body = new HTML::Element 'body';
$section_heading = new HTML::Element ('h2');
pushContent $section_heading $calendar->caption;
pushContent $body $section_heading, $calendar->html, $form;

#
# finally put the head and body together
#
pushContent $doc $head, $body;

#
# and display it
#
print $doc->asHTML;
exit;

#
# callback for new Calendar
#
sub cellfor
{
    ($this_day, $this_month, $this_year) = @_;

    my $cell = new HTML::Element 'form', Method=>'Post', Action=>"t_base.cgi";
    my $list = new HTML::Element 'select', Name=>$this_day;
    pushContent $cell $list;


    for (qw( One Two Three ))
    {
	pushContent $list
	    pushContent {new HTML::Element 'Option'} $_;
    } 

    $cell;
}