1CGI::Pretty(3) User Contributed Perl Documentation CGI::Pretty(3)
2
3
4
6 CGI::Pretty - module to produce nicely formatted HTML code
7
9 use CGI::Pretty qw( :html3 );
10
11 # Print a table with a single data element
12 print table( TR( td( "foo" ) ) );
13
15 CGI::Pretty is a module that derives from CGI. It's sole function is
16 to allow users of CGI to output nicely formatted HTML code.
17
18 When using the CGI module, the following code:
19 print table( TR( td( "foo" ) ) );
20
21 produces the following output:
22 <TABLE><TR><TD>foo</TD></TR></TABLE>
23
24 If a user were to create a table consisting of many rows and many
25 columns, the resultant HTML code would be quite difficult to read since
26 it has no carriage returns or indentation.
27
28 CGI::Pretty fixes this problem. What it does is add a carriage return
29 and indentation to the HTML code so that one can easily read it.
30
31 print table( TR( td( "foo" ) ) );
32
33 now produces the following output:
34 <TABLE>
35 <TR>
36 <TD>foo</TD>
37 </TR>
38 </TABLE>
39
40 Recommendation for when to use CGI::Pretty
41 CGI::Pretty is far slower than using CGI.pm directly. A benchmark
42 showed that it could be about 10 times slower. Adding newlines and
43 spaces may alter the rendered appearance of HTML. Also, the extra
44 newlines and spaces also make the file size larger, making the files
45 take longer to download.
46
47 With all those considerations, it is recommended that CGI::Pretty be
48 used primarily for debugging.
49
50 Tags that won't be formatted
51 The following tags are not formatted: <a>, <pre>, <code>, <script>,
52 <textarea>, and <td>. If these tags were formatted, the user would see
53 the extra indentation on the web browser causing the page to look
54 different than what would be expected. If you wish to add more tags to
55 the list of tags that are not to be touched, push them onto the @AS_IS
56 array:
57
58 push @CGI::Pretty::AS_IS,qw(XMP);
59
60 Customizing the Indenting
61 If you wish to have your own personal style of indenting, you can
62 change the $INDENT variable:
63
64 $CGI::Pretty::INDENT = "\t\t";
65
66 would cause the indents to be two tabs.
67
68 Similarly, if you wish to have more space between lines, you may change
69 the $LINEBREAK variable:
70
71 $CGI::Pretty::LINEBREAK = "\n\n";
72
73 would create two carriage returns between lines.
74
75 If you decide you want to use the regular CGI indenting, you can easily
76 do the following:
77
78 $CGI::Pretty::INDENT = $CGI::Pretty::LINEBREAK = "";
79
81 Brian Paulsen <Brian@ThePaulsens.com>, with minor modifications by
82 Lincoln Stein <lstein@cshl.org> for incorporation into the CGI.pm
83 distribution.
84
85 Copyright 1999, Brian Paulsen. All rights reserved.
86
87 This library is free software; you can redistribute it and/or modify it
88 under the same terms as Perl itself.
89
90 Bug reports and comments to Brian@ThePaulsens.com. You can also write
91 to lstein@cshl.org, but this code looks pretty hairy to me and I'm not
92 sure I understand it!
93
95 CGI
96
97
98
99perl v5.16.3 2011-01-24 CGI::Pretty(3)