blob: 9e528ab747306010a81041f3b840eefc90a90814 [file] [log] [blame]
Fred Drake7313b031998-07-24 20:34:59 +00001package SynopsisTable;
2
3sub new{
Fred Drake75c6cb92000-09-09 05:53:41 +00004 return bless {names=>'', info=>{}, file=>''};
Fred Drake7313b031998-07-24 20:34:59 +00005}
6
7sub declare{
8 my($self,$name,$key,$type) = @_;
9 if ($self->{names}) {
10 $self->{names} .= ",$name";
11 }
12 else {
13 $self->{names} .= "$name";
14 }
15 $self->{info}{$name} = "$key,$type,";
16}
17
Fred Drake75c6cb92000-09-09 05:53:41 +000018# The 'file' attribute is used to store the filename of the node in which
19# the table will be presented; this assumes that each table will be presented
20# only once, which works for the current use of this object.
21
22sub set_file{
23 my($self, $filename) = @_;
24 $self->{file} = "$filename";
25}
26
27sub get_file{
28 my $self = shift;
29 return $self->{file};
30}
31
Fred Drake7313b031998-07-24 20:34:59 +000032sub set_synopsis{
33 my($self,$name,$synopsis) = @_;
34 my($key,$type,$unused) = split ',', $self->{info}{$name}, 3;
35 $self->{info}{$name} = "$key,$type,$synopsis";
36}
37
38sub get{
39 my($self,$name) = @_;
40 return split /,/, $self->{info}{$name}, 3;
41}
42
43sub show{
44 my $self = shift;
45 my $name;
46 print "names: ", $self->{names}, "\n\n";
47 foreach $name (split /,/, $self->{names}) {
48 my($key,$type,$synopsis) = $self->get($name);
49 print "$name($key) is $type: $synopsis\n";
50 }
51}
52
53sub tohtml{
54 my $self = shift;
Fred Drakecaa79a92001-05-09 15:32:14 +000055 my $oddrow = 1;
56 my $data = "<table class='synopsistable' valign='baseline'>\n";
Fred Drake7313b031998-07-24 20:34:59 +000057 my $name;
58 foreach $name (split /,/, $self->{names}) {
59 my($key,$type,$synopsis) = $self->get($name);
Fred Drakee15956b2000-04-03 04:51:13 +000060 my $link = "<a href='module-$key.html'>";
Fred Drakecaa79a92001-05-09 15:32:14 +000061 $data .= (' <tr'
62 . ($oddrow ? " class='oddrow'>\n " : '>')
Fred Drakee15956b2000-04-03 04:51:13 +000063 . "<td><b><tt class='module'>$link$name</a></tt></b></td>\n"
Fred Drakecaa79a92001-05-09 15:32:14 +000064 . " <td>\&nbsp;</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +000065 . " <td class='synopsis'>$synopsis</td></tr>\n");
Fred Drakecaa79a92001-05-09 15:32:14 +000066 $oddrow = !$oddrow;
Fred Drake7313b031998-07-24 20:34:59 +000067 }
Fred Draked05177f1998-07-29 04:45:23 +000068 $data .= "</table>\n";
Fred Drake7313b031998-07-24 20:34:59 +000069 $data;
70}
71
72
73package testSynopsisTable;
74
75sub test{
76 # this little test is mostly to debug the stuff above, since this is
77 # my first Perl "object".
78 my $st = SynopsisTable->new();
79 $st->declare("sample", "sample", "standard");
80 $st->set_synopsis("sample", "This is a little synopsis....");
81 $st->declare("copy_reg", "copyreg", "standard");
82 $st->set_synopsis("copy_reg", "pickle support stuff");
83 $st->show();
84
85 print "\n\n";
86
87 my $st2 = SynopsisTable->new();
88 $st2->declare("st2module", "st2module", "built-in");
89 $st2->set_synopsis("st2module", "silly little synopsis");
90 $st2->show();
91}
92
931; # This must be the last line -- Perl is bogus!