blob: 6a03dd2866c35d4ab0075c38a79893e9aabdaa88 [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 Drakee15956b2000-04-03 04:51:13 +000055 my $data = "<table class='synopsistable'>\n";
Fred Drake7313b031998-07-24 20:34:59 +000056 my $name;
57 foreach $name (split /,/, $self->{names}) {
58 my($key,$type,$synopsis) = $self->get($name);
Fred Drakee15956b2000-04-03 04:51:13 +000059 my $link = "<a href='module-$key.html'>";
60 $data .= (' <tr>'
61 . "<td><b><tt class='module'>$link$name</a></tt></b></td>\n"
62 . " <td class='synopsis'>$synopsis</td></tr>\n");
Fred Drake7313b031998-07-24 20:34:59 +000063 }
Fred Draked05177f1998-07-29 04:45:23 +000064 $data .= "</table>\n";
Fred Drake7313b031998-07-24 20:34:59 +000065 $data;
66}
67
68
69package testSynopsisTable;
70
71sub test{
72 # this little test is mostly to debug the stuff above, since this is
73 # my first Perl "object".
74 my $st = SynopsisTable->new();
75 $st->declare("sample", "sample", "standard");
76 $st->set_synopsis("sample", "This is a little synopsis....");
77 $st->declare("copy_reg", "copyreg", "standard");
78 $st->set_synopsis("copy_reg", "pickle support stuff");
79 $st->show();
80
81 print "\n\n";
82
83 my $st2 = SynopsisTable->new();
84 $st2->declare("st2module", "st2module", "built-in");
85 $st2->set_synopsis("st2module", "silly little synopsis");
86 $st2->show();
87}
88
891; # This must be the last line -- Perl is bogus!