source: vendor/python/2.5/Doc/perl/SynopsisTable.pm

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 2.5 KB
Line 
1package SynopsisTable;
2
3sub new{
4 return bless {names=>'', info=>{}, file=>''};
5}
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
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
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
32sub 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;
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>/\&amp;/g;
63 $data .= (' <tr'
64 . ($oddrow ? " class='oddrow'>\n " : '>')
65 . "<td><b><tt class='module'>$link$name</a></tt></b></td>\n"
66 . " <td>\&nbsp;</td>\n"
67 . " <td class='synopsis'>$synopsis</td></tr>\n");
68 $oddrow = !$oddrow;
69 }
70 $data .= "</table>\n";
71 $data;
72}
73
74
75package testSynopsisTable;
76
77sub 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
951; # This must be the last line -- Perl is bogus!
Note: See TracBrowser for help on using the repository browser.