| 1 | package SynopsisTable;
|
|---|
| 2 |
|
|---|
| 3 | sub new{
|
|---|
| 4 | return bless {names=>'', info=>{}, file=>''};
|
|---|
| 5 | }
|
|---|
| 6 |
|
|---|
| 7 | sub 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 |
|
|---|
| 18 | # 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 |
|
|---|
| 22 | sub set_file{
|
|---|
| 23 | my($self, $filename) = @_;
|
|---|
| 24 | $self->{file} = "$filename";
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | sub get_file{
|
|---|
| 28 | my $self = shift;
|
|---|
| 29 | return $self->{file};
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | sub 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 |
|
|---|
| 38 | sub get{
|
|---|
| 39 | my($self,$name) = @_;
|
|---|
| 40 | return split /,/, $self->{info}{$name}, 3;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | sub 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 |
|
|---|
| 53 | sub tohtml{
|
|---|
| 54 | my $self = shift;
|
|---|
| 55 | my $oddrow = 1;
|
|---|
| 56 | my $data = "<table class='synopsistable' valign='baseline'>\n";
|
|---|
| 57 | my $name;
|
|---|
| 58 | foreach $name (split /,/, $self->{names}) {
|
|---|
| 59 | my($key,$type,$synopsis) = $self->get($name);
|
|---|
| 60 | my $link = "<a href='module-$key.html'>";
|
|---|
| 61 | $synopsis =~ s/<tex2html_percent_mark>/%/g;
|
|---|
| 62 | $synopsis =~ s/<tex2html_ampersand_mark>/\&/g;
|
|---|
| 63 | $data .= (' <tr'
|
|---|
| 64 | . ($oddrow ? " class='oddrow'>\n " : '>')
|
|---|
| 65 | . "<td><b><tt class='module'>$link$name</a></tt></b></td>\n"
|
|---|
| 66 | . " <td>\ </td>\n"
|
|---|
| 67 | . " <td class='synopsis'>$synopsis</td></tr>\n");
|
|---|
| 68 | $oddrow = !$oddrow;
|
|---|
| 69 | }
|
|---|
| 70 | $data .= "</table>\n";
|
|---|
| 71 | $data;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | package testSynopsisTable;
|
|---|
| 76 |
|
|---|
| 77 | sub test{
|
|---|
| 78 | # this little test is mostly to debug the stuff above, since this is
|
|---|
| 79 | # my first Perl "object".
|
|---|
| 80 | my $st = SynopsisTable->new();
|
|---|
| 81 | $st->declare("sample", "sample", "standard");
|
|---|
| 82 | $st->set_synopsis("sample", "This is a little synopsis....");
|
|---|
| 83 | $st->declare("copy_reg", "copyreg", "standard");
|
|---|
| 84 | $st->set_synopsis("copy_reg", "pickle support stuff");
|
|---|
| 85 | $st->show();
|
|---|
| 86 |
|
|---|
| 87 | print "\n\n";
|
|---|
| 88 |
|
|---|
| 89 | my $st2 = SynopsisTable->new();
|
|---|
| 90 | $st2->declare("st2module", "st2module", "built-in");
|
|---|
| 91 | $st2->set_synopsis("st2module", "silly little synopsis");
|
|---|
| 92 | $st2->show();
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | 1; # This must be the last line -- Perl is bogus!
|
|---|