File: Stream.pm.html

package info (click to toggle)
libhtml-stream-perl 1.60-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 388 kB
  • sloc: perl: 666; makefile: 2
file content (1258 lines) | stat: -rw-r--r-- 48,408 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
<HTML>
<HEAD>
  <TITLE>HTML::Stream 1.54</TITLE>
</HEAD>
<BODY 
       bgcolor="#FFFFFF" link="#CC3366" vlink="#993366" alink="#FF6666">
<FONT FACE="sans-serif" SIZE=-1><A HREF="http://www.zeegee.com" TARGET="_top"><IMG SRC="icons/zeegee.gif" ALT="ZeeGee Software" ALIGN="RIGHT" BORDER="0"></A><A NAME="__TOP__"><H1>HTML::Stream 1.54</H1>
</A><UL>
<LI> <A NAME="menu:NAME"><A HREF="#NAME">NAME</A></A>
<LI> <A NAME="menu:SYNOPSIS"><A HREF="#SYNOPSIS">SYNOPSIS</A></A>
<LI> <A NAME="menu:DESCRIPTION"><A HREF="#DESCRIPTION">DESCRIPTION</A></A>
<LI> <A NAME="menu:INTRODUCTION_the_Neapolitan_dessert_special"><A HREF="#INTRODUCTION_the_Neapolitan_dessert_special">INTRODUCTION (the Neapolitan dessert special)</A></A>
<UL>
<LI> <A NAME="menu:Function_interface"><A HREF="#Function_interface">Function interface</A></A>
<LI> <A NAME="menu:OO_interface_vanilla"><A HREF="#OO_interface_vanilla">OO interface, vanilla</A></A>
<LI> <A NAME="menu:OO_interface_chocolate"><A HREF="#OO_interface_chocolate">OO interface, chocolate</A></A>
<LI> <A NAME="menu:OO_interface_with_whipped_cream"><A HREF="#OO_interface_with_whipped_cream">OO interface, with whipped cream</A></A>
<LI> <A NAME="menu:OO_interface_strawberry"><A HREF="#OO_interface_strawberry">OO interface, strawberry</A></A>
</UL>
<LI> <A NAME="menu:ADVANCED_TOPICS"><A HREF="#ADVANCED_TOPICS">ADVANCED TOPICS</A></A>
<UL>
<LI> <A NAME="menu:Auto-formatting_and_inserting_newlines"><A HREF="#Auto-formatting_and_inserting_newlines">Auto-formatting and inserting newlines</A></A>
<LI> <A NAME="menu:Entities"><A HREF="#Entities">Entities</A></A>
<LI> <A NAME="menu:Auto-escaping_changing_the_way_text_is_escaped"><A HREF="#Auto-escaping_changing_the_way_text_is_escaped">Auto-escaping: changing the way text is escaped</A></A>
<LI> <A NAME="menu:Outputting_HTML_to_things_besides_filehandles"><A HREF="#Outputting_HTML_to_things_besides_filehandles">Outputting HTML to things besides filehandles</A></A>
<LI> <A NAME="menu:Subclassing"><A HREF="#Subclassing">Subclassing</A></A>
</UL>
<LI> <A NAME="menu:PUBLIC_INTERFACE"><A HREF="#PUBLIC_INTERFACE">PUBLIC INTERFACE</A></A>
<UL>
<LI> <A NAME="menu:Functions"><A HREF="#Functions">Functions</A></A>
<UL>
<LI> <A NAME="menu:item:html_escape_TEXT"><A HREF="#item:html_escape_TEXT">html_escape TEXT</A></A>
<LI> <A NAME="menu:item:html_tag_TAG_PARAM_VALUE"><A HREF="#item:html_tag_TAG_PARAM_VALUE">html_tag TAG [, PARAM=&gt;VALUE, ...]</A></A>
<LI> <A NAME="menu:item:html_unescape_TEXT"><A HREF="#item:html_unescape_TEXT">html_unescape TEXT</A></A>
<LI> <A NAME="menu:item:html_unmarkup_TEXT"><A HREF="#item:html_unmarkup_TEXT">html_unmarkup TEXT</A></A>
</UL>
<LI> <A NAME="menu:Vanilla"><A HREF="#Vanilla">Vanilla</A></A>
<UL>
<LI> <A NAME="menu:item:new_PRINTABLE"><A HREF="#item:new_PRINTABLE">new [PRINTABLE] </A></A>
<LI> <A NAME="menu:item:auto_escape_NAME_SUBREF"><A HREF="#item:auto_escape_NAME_SUBREF">auto_escape [NAME|SUBREF]</A></A>
<LI> <A NAME="menu:item:auto_format_ONOFF"><A HREF="#item:auto_format_ONOFF">auto_format ONOFF</A></A>
<LI> <A NAME="menu:item:comment_COMMENT"><A HREF="#item:comment_COMMENT">comment COMMENT</A></A>
<LI> <A NAME="menu:item:ent_ENTITY"><A HREF="#item:ent_ENTITY">ent ENTITY</A></A>
<LI> <A NAME="menu:item:io"><A HREF="#item:io">io</A></A>
<LI> <A NAME="menu:item:nl_COUNT"><A HREF="#item:nl_COUNT">nl [COUNT]</A></A>
<LI> <A NAME="menu:item:tag_TAGNAME_PARAM_VALUE"><A HREF="#item:tag_TAGNAME_PARAM_VALUE">tag TAGNAME [, PARAM=&gt;VALUE, ...]</A></A>
<LI> <A NAME="menu:item:text_TEXT"><A HREF="#item:text_TEXT">text TEXT...</A></A>
<LI> <A NAME="menu:item:text_nbsp_TEXT"><A HREF="#item:text_nbsp_TEXT">text_nbsp TEXT...</A></A>
</UL>
<LI> <A NAME="menu:Strawberry"><A HREF="#Strawberry">Strawberry</A></A>
<UL>
<LI> <A NAME="menu:item:output_ITEM_ITEM"><A HREF="#item:output_ITEM_ITEM">output ITEM,...,ITEM</A></A>
</UL>
<LI> <A NAME="menu:Chocolate"><A HREF="#Chocolate">Chocolate</A></A>
<UL>
<LI> <A NAME="menu:item:accept_tag_TAG"><A HREF="#item:accept_tag_TAG">accept_tag TAG</A></A>
<LI> <A NAME="menu:item:private_tags"><A HREF="#item:private_tags">private_tags </A></A>
<LI> <A NAME="menu:item:set_tag_TAG_TAGINFO"><A HREF="#item:set_tag_TAG_TAGINFO">set_tag TAG, [TAGINFO...]</A></A>
<LI> <A NAME="menu:item:tags"><A HREF="#item:tags">tags </A></A>
</UL>
</UL>
<LI> <A NAME="menu:SUBCLASSES"><A HREF="#SUBCLASSES">SUBCLASSES</A></A>
<UL>
<LI> <A NAME="menu:HTML_Stream_Latin1"><A HREF="#HTML_Stream_Latin1">HTML::Stream::Latin1</A></A>
</UL>
<LI> <A NAME="menu:PERFORMANCE"><A HREF="#PERFORMANCE">PERFORMANCE</A></A>
<LI> <A NAME="menu:VERSION"><A HREF="#VERSION">VERSION</A></A>
<LI> <A NAME="menu:CHANGE_LOG"><A HREF="#CHANGE_LOG">CHANGE LOG</A></A>
<UL>
<LI> <A NAME="menu:item:Version_1_54_2001_08_20"><A HREF="#item:Version_1_54_2001_08_20">Version 1.54   (2001/08/20)</A></A>
<LI> <A NAME="menu:item:Version_1_51_2001_08_16"><A HREF="#item:Version_1_51_2001_08_16">Version 1.51   (2001/08/16)</A></A>
<LI> <A NAME="menu:item:Version_1_47_2000_06_10"><A HREF="#item:Version_1_47_2000_06_10">Version 1.47   (2000/06/10)</A></A>
<LI> <A NAME="menu:item:Version_1_45_1999_02_09"><A HREF="#item:Version_1_45_1999_02_09">Version 1.45   (1999/02/09)</A></A>
<LI> <A NAME="menu:item:Version_1_44_1998_01_14"><A HREF="#item:Version_1_44_1998_01_14">Version 1.44   (1998/01/14)</A></A>
<LI> <A NAME="menu:item:Version_1_41_1998_01_02"><A HREF="#item:Version_1_41_1998_01_02">Version 1.41   (1998/01/02)</A></A>
<LI> <A NAME="menu:item:Version_1_37_1997_02_09"><A HREF="#item:Version_1_37_1997_02_09">Version 1.37   (1997/02/09)</A></A>
<LI> <A NAME="menu:item:Version_1_32_1997_01_12"><A HREF="#item:Version_1_32_1997_01_12">Version 1.32   (1997/01/12)</A></A>
<LI> <A NAME="menu:item:Version_1_29_1996_12_10"><A HREF="#item:Version_1_29_1996_12_10">Version 1.29   (1996/12/10)</A></A>
<LI> <A NAME="menu:item:Version_1_27_1996_12_10"><A HREF="#item:Version_1_27_1996_12_10">Version 1.27   (1996/12/10)</A></A>
<LI> <A NAME="menu:item:Version_1_26_1996_09_27"><A HREF="#item:Version_1_26_1996_09_27">Version 1.26   (1996/09/27)</A></A>
</UL>
<LI> <A NAME="menu:ACKNOWLEDGEMENTS"><A HREF="#ACKNOWLEDGEMENTS">ACKNOWLEDGEMENTS</A></A>
<LI> <A NAME="menu:AUTHOR"><A HREF="#AUTHOR">AUTHOR</A></A>
</UL>


<P><HR>
<A NAME="NAME"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> NAME</H2></A>


<P>HTML::Stream - HTML output stream class, and some markup utilities



<P><HR>
<A NAME="SYNOPSIS"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> SYNOPSIS</H2></A>


<P>Here's small sample of some of the non-OO ways you can use this module:

<FONT SIZE=3 FACE="courier"><PRE>
      use HTML::Stream qw(:funcs);
      
      print html_tag('A', HREF=&gt;$link);     
      print html_escape(&quot;&lt;&lt;Hello &amp; welcome!&gt;&gt;&quot;);      
</PRE></FONT>

<P>And some of the OO ways as well:

<FONT SIZE=3 FACE="courier"><PRE>
      use HTML::Stream;
      $HTML = new HTML::Stream \*STDOUT;
      
      # The vanilla interface...
      $HTML-&gt;tag('A', HREF=&gt;&quot;$href&quot;);
      $HTML-&gt;tag('IMG', SRC=&gt;&quot;logo.gif&quot;, ALT=&gt;&quot;LOGO&quot;);
      $HTML-&gt;text($copyright);
      $HTML-&gt;tag('_A');
      
      # The chocolate interface...
      $HTML -&gt; A(HREF=&gt;&quot;$href&quot;);
      $HTML -&gt; IMG(SRC=&gt;&quot;logo.gif&quot;, ALT=&gt;&quot;LOGO&quot;);
      $HTML -&gt; t($caption);
      $HTML -&gt; _A;
       
      # The chocolate interface, with whipped cream...
      $HTML -&gt; A(HREF=&gt;&quot;$href&quot;)
            -&gt; IMG(SRC=&gt;&quot;logo.gif&quot;, ALT=&gt;&quot;LOGO&quot;)
            -&gt; t($caption)
            -&gt; _A;
</PRE></FONT>
<FONT SIZE=3 FACE="courier"><PRE>
      # The strawberry interface...
      output $HTML [A, HREF=&gt;&quot;$href&quot;], 
                   [IMG, SRC=&gt;&quot;logo.gif&quot;, ALT=&gt;&quot;LOGO&quot;],
                   $caption,
                   [_A];
</PRE></FONT>


<P><HR>
<A NAME="DESCRIPTION"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> DESCRIPTION</H2></A>


<P>The <B>HTML::Stream</B> module provides you with an object-oriented
(and subclassable) way of outputting HTML.  Basically, you open up 
an &quot;HTML stream&quot; on an existing filehandle, and then do all of your  
output to the HTML stream.  You can intermix HTML-stream-output and 
ordinary-print-output, if you like.


<P>There's even a small built-in subclass, <B>HTML::Stream::Latin1</B>, which can
handle Latin-1 input right out of the box.   But all in good time...



<P><HR>
<A NAME="INTRODUCTION_the_Neapolitan_dessert_special"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> INTRODUCTION (the Neapolitan dessert special)</H2></A>



<P><HR>
<A NAME="Function_interface"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Function interface</H3></A>


<P>Let's start out with the simple stuff.
This module provides a collection of non-OO utility functions
for escaping HTML text and producing HTML tags, like this:

<FONT SIZE=3 FACE="courier"><PRE>
    use HTML::Stream qw(:funcs);        # imports functions from @EXPORT_OK
    
    print html_tag(A, HREF=&gt;$url);
    print '&amp;copy; 1996 by', html_escape($myname), '!';
    print html_tag('/A');
</PRE></FONT>

<P>By the way: that last line could be rewritten as:

<FONT SIZE=3 FACE="courier"><PRE>
    print html_tag(_A);
</PRE></FONT>

<P>And if you need to get a parameter in your tag that doesn't have an
associated value, supply the <I>undefined</I> value (<I>not</I> the empty string!):

<FONT SIZE=3 FACE="courier"><PRE>
    print html_tag(TD, NOWRAP=&gt;undef, ALIGN=&gt;'LEFT');
    
         &lt;TD NOWRAP ALIGN=LEFT&gt;
    
    print html_tag(IMG, SRC=&gt;'logo.gif', ALT=&gt;'');
    
         &lt;IMG SRC=&quot;logo.gif&quot; ALT=&quot;&quot;&gt;
</PRE></FONT>

<P>There are also some routines for reversing the process, like:

<FONT SIZE=3 FACE="courier"><PRE>
    $text = &quot;This &lt;i&gt;isn't&lt;/i&gt; &amp;quot;fun&amp;quot;...&quot;;    
    print html_unmarkup($text);
       
         This isn't &amp;quot;fun&amp;quot;...
      
    print html_unescape($text);
       
         This isn't &quot;fun&quot;...
</PRE></FONT>

<P><I>Yeah, yeah, yeah</I>, I hear you cry.  <I>We've seen this stuff before.</I>
But wait!  There's more...



<P><HR>
<A NAME="OO_interface_vanilla"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> OO interface, vanilla</H3></A>


<P>Using the function interface can be tedious... so we also
provide an <B>&quot;HTML output stream&quot;</B> class.  Messages to an instance of
that class generally tell that stream to output some HTML.  Here's the
above example, rewritten using HTML streams:

<FONT SIZE=3 FACE="courier"><PRE>
    use HTML::Stream;
    $HTML = new HTML::Stream \*STDOUT;
    
    $HTML-&gt;tag(A, HREF=&gt;$url);
    $HTML-&gt;ent('copy');
    $HTML-&gt;text(&quot; 1996 by $myname!&quot;);
    $HTML-&gt;tag(_A);
</PRE></FONT>

<P>As you've probably guessed:

<FONT SIZE=3 FACE="courier"><PRE>
    text()   Outputs some text, which will be HTML-escaped.
    
    tag()    Outputs an ordinary tag, like &lt;A&gt;, possibly with parameters.
             The parameters will all be HTML-escaped automatically.
     
    ent()    Outputs an HTML entity, like the &amp;copy; or &amp;lt; .
             You mostly don't need to use it; you can often just put the 
             Latin-1 representation of the character in the text().
</PRE></FONT>

<P>You might prefer to use <CODE>t()</CODE> and <CODE>e()</CODE> instead of <CODE>text()</CODE> 
and <CODE>ent()</CODE>: they're absolutely identical, and easier to type:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML -&gt; tag(A, HREF=&gt;$url);
    $HTML -&gt; e('copy');
    $HTML -&gt; t(&quot; 1996 by $myname!&quot;);
    $HTML -&gt; tag(_A);
</PRE></FONT>

<P>Now, it wouldn't be nice to give you those <CODE>text()</CODE> and <CODE>ent()</CODE> shortcuts
without giving you one for <CODE>tag()</CODE>, would it?  Of course not...



<P><HR>
<A NAME="OO_interface_chocolate"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> OO interface, chocolate</H3></A>


<P>The known HTML tags are even given their own <B>tag-methods,</B> compiled on 
demand.  The above code could be written even more compactly as:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML -&gt; A(HREF=&gt;$url);
    $HTML -&gt; e('copy');
    $HTML -&gt; t(&quot; 1996 by $myname!&quot;);
    $HTML -&gt; _A;
</PRE></FONT>

<P>As you've probably guessed:

<FONT SIZE=3 FACE="courier"><PRE>
    A(HREF=&gt;$url)   ==   tag(A, HREF=&gt;$url)   ==   &lt;A HREF=&quot;/the/url&quot;&gt;
    _A              ==   tag(_A)              ==   &lt;/A&gt;
</PRE></FONT>

<P>All of the autoloaded &quot;tag-methods&quot; use the tagname in <I>all-uppercase</I>.
A <CODE>&quot;_&quot;</CODE> prefix on any tag-method means that an end-tag is desired.
The <CODE>&quot;_&quot;</CODE> was chosen for several reasons: 
(1) it's short and easy to type,
(2) it doesn't produce much visual clutter to look at,
(3) <CODE>_TAG</CODE> looks a little like <CODE>/TAG</CODE> because of the straight line.



<UL>
<P><LI>
<P><I>I know, I know... it looks like a private method.
You get used to it.  Really.</I>

</UL>


<P>I should stress that this module will only auto-create tag methods
for <B>known</B> HTML tags.  So you're protected from typos like this
(which will cause a fatal exception at run-time):

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML -&gt; IMGG(SRC=&gt;$src);
</PRE></FONT>

<P>(You're not yet protected from illegal tag parameters, but it's a start, 
ain't it?)


<P>If you need to make a tag known (sorry, but this is currently a 
<I>global</I> operation, and not stream-specific), do this:

<FONT SIZE=3 FACE="courier"><PRE>
    accept_tag HTML::Stream 'MARQUEE';       # for you MSIE fans...
</PRE></FONT>

<P><B>Note: there is no corresponding &quot;reject_tag&quot;.</B>  I thought and thought
about it, and could not convince myself that such a method would 
do anything more useful than cause other people's modules to suddenly
stop working because some bozo function decided to reject the <CODE>FONT</CODE> tag.



<P><HR>
<A NAME="OO_interface_with_whipped_cream"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> OO interface, with whipped cream</H3></A>


<P>In the grand tradition of C++, output method chaining is supported
in both the Vanilla Interface and the Chocolate Interface.  
So you can (and probably should) write the above code as:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML -&gt; A(HREF=&gt;$url) 
          -&gt; e('copy') -&gt; t(&quot; 1996 by $myname!&quot;) 
          -&gt; _A;
</PRE></FONT>

<P><I>But wait!  Neapolitan ice cream has one more flavor...</I>



<P><HR>
<A NAME="OO_interface_strawberry"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> OO interface, strawberry</H3></A>


<P>I was jealous of the compact syntax of HTML::AsSubs, but I didn't
want to worry about clogging the namespace with a lot of functions
like p(), a(), etc. (especially when markup-functions like tr() conflict
with existing Perl functions).  So I came up with this:

<FONT SIZE=3 FACE="courier"><PRE>
    output $HTML [A, HREF=&gt;$url], &quot;Here's my $caption&quot;, [_A];
</PRE></FONT>

<P>Conceptually, arrayrefs are sent to <CODE>html_tag()</CODE>, and strings to 
<CODE>html_escape()</CODE>.



<P><HR>
<A NAME="ADVANCED_TOPICS"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> ADVANCED TOPICS</H2></A>



<P><HR>
<A NAME="Auto-formatting_and_inserting_newlines"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Auto-formatting and inserting newlines</H3></A>


<P><I>Auto-formatting</I> is the name I give to the Chocolate Interface feature
whereby newlines (and maybe, in the future, other things)
are inserted before or after the tags you output in order to make 
your HTML more readable.  So, by default, this:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML -&gt; HTML 
          -&gt; HEAD  
          -&gt; TITLE -&gt; t(&quot;Hello!&quot;) -&gt; _TITLE 
          -&gt; _HEAD
          -&gt; BODY(BGCOLOR=&gt;'#808080');
</PRE></FONT>

<P>Actually produces this:

<FONT SIZE=3 FACE="courier"><PRE>
    &lt;HTML&gt;&lt;HTML&gt;
    &lt;HEAD&gt;
    &lt;TITLE&gt;Hello!&lt;/TITLE&gt;
    &lt;/HEAD&gt;
    &lt;BODY BGCOLOR=&quot;#808080&quot;&gt;
</PRE></FONT>

<P><B>To turn off autoformatting altogether</B> on a given HTML::Stream object,
use the <CODE>auto_format()</CODE> method:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML-&gt;auto_format(0);        # stop autoformatting!
</PRE></FONT>

<P><B>To change whether a newline is automatically output</B> before/after the 
begin/end form of a tag at a <B>global</B> level, use <CODE>set_tag()</CODE>:

<FONT SIZE=3 FACE="courier"><PRE>
    HTML::Stream-&gt;set_tag('B', Newlines=&gt;15);   # 15 means &quot;\n&lt;B&gt;\n \n&lt;/B&gt;\n&quot;
    HTML::Stream-&gt;set_tag('I', Newlines=&gt;7);    # 7 means  &quot;\n&lt;I&gt;\n \n&lt;/I&gt;  &quot;
</PRE></FONT>

<P><B>To change whether a newline is automatically output</B> before/after the 
begin/end form of a tag <B>for a given stream</B> level, give the stream
its own private &quot;tag info&quot; table, and then use <CODE>set_tag()</CODE>:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML-&gt;private_tags;
    $HTML-&gt;set_tag('B', Newlines=&gt;0);     # won't affect anyone else!
</PRE></FONT>

<P><B>To output newlines explicitly</B>, just use the special <CODE>nl</CODE> method
in the Chocolate Interface:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML-&gt;nl;     # one newline
    $HTML-&gt;nl(6);  # six newlines
</PRE></FONT>

<P>I am sometimes asked, &quot;why don't you put more newlines in automatically?&quot;
Well, mostly because...



<UL>
<P><LI>
<P>Sometimes you'll be outputting stuff inside a <CODE>PRE</CODE> environment.

<P><LI>
<P>Sometimes you really do want to jam things (like images, or table
cell delimiters and the things they contain) right up against each other.

</UL>


<P>So I've stuck to outputting newlines in places where it's most likely
to be harmless. 



<P><HR>
<A NAME="Entities"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Entities</H3></A>


<P>As shown above, You can use the <CODE>ent()</CODE> (or <CODE>e()</CODE>) method to output 
an entity:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML-&gt;t('Copyright ')-&gt;e('copy')-&gt;t(' 1996 by Me!');
</PRE></FONT>

<P>But this can be a pain, particularly for generating output with
non-ASCII characters:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML -&gt; t('Copyright ') 
          -&gt; e('copy') 
          -&gt; t(' 1996 by Fran') -&gt; e('ccedil') -&gt; t('ois, Inc.!');
</PRE></FONT>

<P>Granted, Europeans can always type the 8-bit characters directly in
their Perl code, and just have this:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML -&gt; t(&quot;Copyright \251 1996 by Fran\347ois, Inc.!');
</PRE></FONT>

<P>But folks without 8-bit text editors can find this kind of output
cumbersome to generate.  Sooooooooo...



<P><HR>
<A NAME="Auto-escaping_changing_the_way_text_is_escaped"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Auto-escaping: changing the way text is escaped</H3></A>


<P><I>Auto-escaping</I> is the name I give to the act of taking an &quot;unsafe&quot;
string (one with &quot;&gt;&quot;, &quot;&amp;&quot;, etc.), and magically outputting &quot;safe&quot; HTML.


<P>The default &quot;auto-escape&quot; behavior of an HTML stream can be a drag if
you've got a lot character entities that you want to output, or if 
you're using the Latin-1 character set, or some other input encoding.  
Fortunately, you can use the <CODE>auto_escape()</CODE> method to change the 
way a particular HTML::Stream works at any time.


<P>First, here's a couple of special invocations:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML-&gt;auto_escape('ALL');      # Default; escapes [&lt;&gt;&quot;&amp;] and 8-bit chars.
    $HTML-&gt;auto_escape('LATIN_1');  # Like ALL, but uses Latin-1 entities
                                    #   instead of decimal equivalents.
    $HTML-&gt;auto_escape('NON_ENT');  # Like ALL, but leaves &quot;&amp;&quot; alone.
</PRE></FONT>

<P>You can also install your own auto-escape function (note
that you might very well want to install it for just a little bit
only, and then de-install it):

<FONT SIZE=3 FACE="courier"><PRE>
    sub my_auto_escape {
        my $text = shift;
	HTML::Entities::encode($text);     # start with default
        $text =~ s/\(c\)/&amp;copy;/ig;        # (C) becomes copyright
        $text =~ s/\\,(c)/\&amp;$1cedil;/ig;   # \,c becomes a cedilla
 	$text;
    }
    
    # Start using my auto-escape:
    my $old_esc = $HTML-&gt;auto_escape(\&amp;my_auto_escape);  
    
    # Output some stuff:
    $HTML-&gt; IMG(SRC=&gt;'logo.gif', ALT=&gt;'Fran\,cois, Inc');
    output $HTML 'Copyright (C) 1996 by Fran\,cois, Inc.!';
    
    # Stop using my auto-escape:
    $HTML-&gt;auto_escape($old_esc);
</PRE></FONT>

<P>If you find yourself in a situation where you're doing this a lot,
a better way is to create a <B>subclass</B> of HTML::Stream which installs
your custom function when constructed.  For an example, see the 
<B>HTML::Stream::Latin1</B> subclass in this module.



<P><HR>
<A NAME="Outputting_HTML_to_things_besides_filehandles"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Outputting HTML to things besides filehandles</H3></A>


<P>As of Revision 1.21, you no longer need to supply <CODE>new()</CODE> with a 
filehandle: <I>any object that responds to a print() method will do</I>.
Of course, this includes <B>blessed</B> FileHandles, and IO::Handles.


<P>If you supply a GLOB reference (like <CODE>\*STDOUT</CODE>) or a string (like
<CODE>&quot;Module::FH&quot;</CODE>), HTML::Stream will automatically create an invisible
object for talking to that filehandle (I don't dare bless it into a
FileHandle, since the underlying descriptor would get closed when 
the HTML::Stream is destroyed, and you might not want that).


<P>You say you want to print to a string?  For kicks and giggles, try this:

<FONT SIZE=3 FACE="courier"><PRE>
    package StringHandle;
    sub new {
	my $self = '';
	bless \$self, shift;
    }
    sub print {
        my $self = shift;
        $$self .= join('', @_);
    }
    
  
    package main;
    use HTML::Stream;
    
    my $SH = new StringHandle;
    my $HTML = new HTML::Stream $SH;
    $HTML -&gt; H1 -&gt; t(&quot;Hello &amp; &lt;&lt;welcome&gt;&gt;!&quot;) -&gt; _H1;
    print &quot;PRINTED STRING: &quot;, $$SH, &quot;\n&quot;;
</PRE></FONT>


<P><HR>
<A NAME="Subclassing"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Subclassing</H3></A>


<P>This is where you can make your application-specific HTML-generating code
<I>much</I> easier to look at.  Consider this:

<FONT SIZE=3 FACE="courier"><PRE>
    package MY::HTML;
    @ISA = qw(HTML::Stream);
     
    sub Aside {
	$_[0] -&gt; FONT(SIZE=&gt;-1) -&gt; I;
    }
    sub _Aside {
	$_[0] -&gt; _I -&gt; _FONT;
    }
</PRE></FONT>

<P>Now, you can do this:

<FONT SIZE=3 FACE="courier"><PRE>
    my $HTML = new MY::HTML \*STDOUT;
    
    $HTML -&gt; Aside
          -&gt; t(&quot;Don't drink the milk, it's spoiled... pass it on...&quot;)
          -&gt; _Aside;
</PRE></FONT>

<P>If you're defining these markup-like, chocolate-interface-style functions,
I recommend using mixed case with a leading capital.  You probably 
shouldn't use all-uppercase, since that's what this module uses for
real HTML tags.



<P><HR>
<A NAME="PUBLIC_INTERFACE"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> PUBLIC INTERFACE</H2></A>



<P><HR>
<A NAME="Functions"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Functions</H3></A>



<DL>
<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:html_escape"><A NAME="item:html_escape_TEXT">html_escape TEXT</A></A></B></DT>
<DD>
Given a TEXT string, turn the text into valid HTML by escaping &quot;unsafe&quot; 
characters.  Currently, the &quot;unsafe&quot; characters are 8-bit characters plus:

<FONT SIZE=3 FACE="courier"><PRE>
    &lt;  &gt;  =  &amp;
</PRE></FONT>

<P><B>Note:</B> provided for convenience and backwards-compatibility only.
You may want to use the more-powerful <B>HTML::Entities::encode</B>
function instead.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:html_tag"><A NAME="item:html_tag_TAG_PARAM_VALUE">html_tag TAG [, PARAM=&gt;VALUE, ...]</A></A></B></DT>
<DD>
Return the text for a given TAG, possibly with parameters.
As an efficiency hack, only the values are HTML-escaped currently:
it is assumed that the tag and parameters will already be safe.


<P>For convenience and readability, you can say <CODE>_A</CODE> instead of <CODE>&quot;/A&quot;</CODE>
for the first tag, if you're into barewords.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:html_unescape"><A NAME="item:html_unescape_TEXT">html_unescape TEXT</A></A></B></DT>
<DD>
Remove angle-tag markup, and convert the standard ampersand-escapes
(<CODE>lt</CODE>, <CODE>gt</CODE>, <CODE>amp</CODE>, <CODE>quot</CODE>, and <CODE>#ddd</CODE>) into ASCII characters.


<P><B>Note:</B> provided for convenience and backwards-compatibility only.
You may want to use the more-powerful <B>HTML::Entities::decode</B>
function instead: unlike this function, it can collapse entities
like <CODE>copy</CODE> and <CODE>ccedil</CODE> into their Latin-1 byte values.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:html_unmarkup"><A NAME="item:html_unmarkup_TEXT">html_unmarkup TEXT</A></A></B></DT>
<DD>
Remove angle-tag markup from TEXT, but do not convert ampersand-escapes.  
Cheesy, but theoretically useful if you want to, say, incorporate
externally-provided HTML into a page you're generating, and are worried
that the HTML might contain undesirable markup.

</DL>



<P><HR>
<A NAME="Vanilla"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Vanilla</H3></A>



<DL>
<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:new"><A NAME="item:new_PRINTABLE">new [PRINTABLE]</A></A></B></DT>
<DD>
<I>Class method.</I>
Create a new HTML output stream.


<P>The PRINTABLE may be a FileHandle, a glob reference, or any object
that responds to a <CODE>print()</CODE> message.
If no PRINTABLE is given, does a select() and uses that.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:auto_escape"><A NAME="item:auto_escape_NAME_SUBREF">auto_escape [NAME|SUBREF]</A></A></B></DT>
<DD>
<I>Instance method.</I>
Set the auto-escape function for this HTML stream.


<P>If the argument is a subroutine reference SUBREF, then that subroutine 
will be used.  Declare such subroutines like this:

<FONT SIZE=3 FACE="courier"><PRE>
    sub my_escape {
	my $text = shift;     # it's passed in the first argument
        ...
        $text;
    }
</PRE></FONT>

<P>If a textual NAME is given, then one of the appropriate built-in 
functions is used.  Possible values are:



<DL>
<P><DT><B><A NAME="item:ALL">ALL</A></B></DT>
<DD>
Default for HTML::Stream objects.  This escapes angle brackets, 
ampersands, double-quotes, and 8-bit characters.  8-bit characters 
are escaped using decimal entity codes (like <CODE>#123</CODE>).

<P><DT><B><A NAME="item:LATIN_1">LATIN_1</A></B></DT>
<DD>
Like <CODE>&quot;ALL&quot;</CODE>, but uses Latin-1 entity names (like <CODE>ccedil</CODE>) instead of
decimal entity codes to escape characters.  This makes the HTML more readable
but it is currently not advised, as &quot;older&quot; browsers (like Netscape 2.0)
do not recognize many of the ISO-8859-1 entity names (like <CODE>deg</CODE>).


<P><B>Warning:</B> If you specify this option, you'll find that it attempts
to &quot;require&quot; <B>HTML::Entities</B> at run time.  That's because I didn't want 
to <I>force</I> you to have that module just to use the rest of HTML::Stream.
To pick up problems at compile time, you are advised to say:

<FONT SIZE=3 FACE="courier"><PRE>
    use HTML::Stream;
    use HTML::Entities;
</PRE></FONT>

<P>in your source code.

<P><DT><B><A NAME="item:NON_ENT">NON_ENT</A></B></DT>
<DD>
Like <CODE>&quot;ALL&quot;</CODE>, except that ampersands (&amp;) are <I>not</I> escaped.
This allows you to use &amp;-entities in your text strings, while having
everything else safely escaped:

<FONT SIZE=3 FACE="courier"><PRE>
    output $HTML &quot;If A is an acute angle, then A &gt; 90&amp;deg;&quot;;
</PRE></FONT>
</DL>


<P>Returns the previously-installed function, in the manner of <CODE>select()</CODE>.
No arguments just returns the currently-installed function.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:auto_format"><A NAME="item:auto_format_ONOFF">auto_format ONOFF</A></A></B></DT>
<DD>
<I>Instance method.</I>
Set the auto-formatting characteristics for this HTML stream.
Currently, all you can do is supply a single defined boolean
argument, which turns auto-formatting ON (1) or OFF (0). 
The self object is returned.


<P>Please use no other values; they are reserved for future use.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:comment"><A NAME="item:comment_COMMENT">comment COMMENT</A></A></B></DT>
<DD>
<I>Instance method.</I>
Output an HTML comment.
As of 1.29, a newline is automatically appended.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:ent"><A NAME="item:ent_ENTITY">ent ENTITY</A></A></B></DT>
<DD>
<I>Instance method.</I>
Output an HTML entity.  For example, here's how you'd output a 
non-breaking space:

<FONT SIZE=3 FACE="courier"><PRE>
      $html-&gt;ent('nbsp');
</PRE></FONT>

<P>You may abbreviate this method name as <CODE>e</CODE>:

<FONT SIZE=3 FACE="courier"><PRE>
      $html-&gt;e('nbsp');
</PRE></FONT>

<P><B>Warning:</B> this function assumes that the entity argument is legal.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:io">io</A></B></DT>
<DD>
Return the underlying output handle for this HTML stream.
All you can depend upon is that it is some kind of object
which responds to a print() message:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML-&gt;io-&gt;print(&quot;This is not auto-escaped or nuthin!&quot;);
</PRE></FONT>
<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:nl"><A NAME="item:nl_COUNT">nl [COUNT]</A></A></B></DT>
<DD>
<I>Instance method.</I>
Output COUNT newlines.  If undefined, COUNT defaults to 1.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:tag"><A NAME="item:tag_TAGNAME_PARAM_VALUE">tag TAGNAME [, PARAM=&gt;VALUE, ...]</A></A></B></DT>
<DD>
<I>Instance method.</I>
Output a tag.  Returns the self object, to allow method chaining.
You can say <CODE>_A</CODE> instead of <CODE>&quot;/A&quot;</CODE>, if you're into barewords.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:text"><A NAME="item:text_TEXT">text TEXT...</A></A></B></DT>
<DD>
<I>Instance method.</I>
Output some text.  You may abbreviate this method name as <CODE>t</CODE>:

<FONT SIZE=3 FACE="courier"><PRE>
      $html-&gt;t('Hi there, ', $yournamehere, '!');
</PRE></FONT>

<P>Returns the self object, to allow method chaining.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:text_nbsp"><A NAME="item:text_nbsp_TEXT">text_nbsp TEXT...</A></A></B></DT>
<DD>
<I>Instance method.</I>
Output some text, but with all spaces output as non-breaking-space
characters: 

<FONT SIZE=3 FACE="courier"><PRE>
      $html-&gt;t(&quot;To list your home directory, type: &quot;)
           -&gt;text_nbsp(&quot;ls -l ~yourname.&quot;)
</PRE></FONT>

<P>Returns the self object, to allow method chaining.

</DL>



<P><HR>
<A NAME="Strawberry"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Strawberry</H3></A>



<DL>
<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:output"><A NAME="item:output_ITEM_ITEM">output ITEM,...,ITEM</A></A></B></DT>
<DD>
<I>Instance method.</I>
Go through the items.  If an item is an arrayref, treat it like
the array argument to html_tag() and output the result.  If an item
is a text string, escape the text and output the result.  Like this:

<FONT SIZE=3 FACE="courier"><PRE>
     output $HTML [A, HREF=&gt;$url], &quot;Here's my $caption!&quot;, [_A];
</PRE></FONT>
</DL>



<P><HR>
<A NAME="Chocolate"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Chocolate</H3></A>



<DL>
<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:accept_tag"><A NAME="item:accept_tag_TAG">accept_tag TAG</A></A></B></DT>
<DD>
<I>Class method.</I>
Declares that the tag is to be accepted as valid HTML (if it isn't already).
For example, this...

<FONT SIZE=3 FACE="courier"><PRE>
     # Make sure methods MARQUEE and _MARQUEE are compiled on demand:
     HTML::Stream-&gt;accept_tag('MARQUEE'); 
</PRE></FONT>

<P>...gives the Chocolate Interface permission to create (via AUTOLOAD)
definitions for the MARQUEE and _MARQUEE methods, so you can then say:

<FONT SIZE=3 FACE="courier"><PRE>
     $HTML -&gt; MARQUEE -&gt; t(&quot;Hi!&quot;) -&gt; _MARQUEE;
</PRE></FONT>

<P>If you want to set the default attribute of the tag as well, you can
do so via the set_tag() method instead; it will effectively do an
accept_tag() as well.

<FONT SIZE=3 FACE="courier"><PRE>
     # Make sure methods MARQUEE and _MARQUEE are compiled on demand,
     #   *and*, set the characteristics of that tag.
     HTML::Stream-&gt;set_tag('MARQUEE', Newlines=&gt;9);
</PRE></FONT>
<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:private_tags">private_tags</A></B></DT>
<DD>
<I>Instance method.</I>
Normally, HTML streams use a reference to a global table of tag
information to determine how to do such things as auto-formatting,
and modifications made to that table by <CODE>set_tag</CODE> will
affect everyone.


<P>However, if you want an HTML stream to have a private copy of that
table to munge with, just send it this message after creating it.  
Like this:

<FONT SIZE=3 FACE="courier"><PRE>
    my $HTML = new HTML::Stream \*STDOUT;
    $HTML-&gt;private_tags;
</PRE></FONT>

<P>Then, you can say stuff like:

<FONT SIZE=3 FACE="courier"><PRE>
    $HTML-&gt;set_tag('PRE',   Newlines=&gt;0);
    $HTML-&gt;set_tag('BLINK', Newlines=&gt;9);
</PRE></FONT>

<P>And it won't affect anyone else's <I>auto-formatting</I> (although they will 
possibly be able to use the BLINK tag method without a fatal
exception <CODE>:-(</CODE> ).


<P>Returns the self object.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:set_tag"><A NAME="item:set_tag_TAG_TAGINFO">set_tag TAG, [TAGINFO...]</A></A></B></DT>
<DD>
<I>Class/instance method.</I>
Accept the given TAG in the Chocolate Interface, and (if TAGINFO
is given) alter its characteristics when being output.



<UL>
<P><LI>
<P><B>If invoked as a class method,</B> this alters the &quot;master tag table&quot;,
and allows a new tag to be supported via an autoloaded method:

<FONT SIZE=3 FACE="courier"><PRE>
     HTML::Stream-&gt;set_tag('MARQUEE', Newlines=&gt;9);
</PRE></FONT>

<P>Once you do this, <I>all</I> HTML streams you open from then on 
will allow that tag to be output in the chocolate interface.

<P><LI>
<P><B>If invoked as an instance method,</B> this alters the &quot;tag table&quot; referenced
by that HTML stream, usually for the purpose of affecting things like
the auto-formatting on that HTML stream.  


<P><B>Warning:</B> by default, an HTML stream just references the &quot;master tag table&quot; 
(this makes <CODE>new()</CODE> more efficient), so <I>by default, the 
instance method will behave exactly like the class method.</I>

<FONT SIZE=3 FACE="courier"><PRE>
     my $HTML = new HTML::Stream \*STDOUT;
     $HTML-&gt;set_tag('BLINK', Newlines=&gt;0);  # changes it for others!
</PRE></FONT>

<P>If you want to diddle with <I>one</I> stream's auto-formatting <I>only,</I> 
you'll need to give that stream its own <I>private</I> tag table.  Like this:

<FONT SIZE=3 FACE="courier"><PRE>
     my $HTML = new HTML::Stream \*STDOUT;
     $HTML-&gt;private_tags;
     $HTML-&gt;set_tag('BLINK', Newlines=&gt;0);  # doesn't affect other streams
</PRE></FONT>

<P><B>Note:</B> this will still force an default entry for BLINK in the <I>master</I> 
tag table: otherwise, we'd never know that it was legal to AUTOLOAD a 
BLINK method.   However, it will only alter the <I>characteristics</I> of the 
BLINK tag (like auto-formatting) in the <I>object's</I> tag table.

</UL>


<P>The TAGINFO, if given, is a set of key=&gt;value pairs with the following 
possible keys:



<DL>
<P><DT><B><A NAME="item:Newlines">Newlines</A></B></DT>
<DD>
Assumed to be a number which encodes how newlines are to be output 
before/after a tag.   The value is the logical OR (or sum) of a set of flags:

<FONT SIZE=3 FACE="courier"><PRE>
     0x01    newline before &lt;TAG&gt;         .&lt;TAG&gt;.     .&lt;/TAG&gt;.    
     0x02    newline after &lt;TAG&gt;          |     |     |      |
     0x04    newline before &lt;/TAG&gt;        1     2     4      8
     0x08    newline after &lt;/TAG&gt;    
</PRE></FONT>

<P>Hence, to output BLINK environments which are preceded/followed by newlines:

<FONT SIZE=3 FACE="courier"><PRE>
     set_tag HTML::Stream 'BLINK', Newlines=&gt;9;
</PRE></FONT>
</DL>


<P>Returns the self object on success.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:tags">tags</A></B></DT>
<DD>
<I>Class/instance method.</I>
Returns an unsorted list of all tags in the class/instance tag table 
(see <CODE>set_tag</CODE> for class/instance method differences).

</DL>



<P><HR>
<A NAME="SUBCLASSES"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> SUBCLASSES</H2></A>



<P><HR>
<A NAME="HTML_Stream_Latin1"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> HTML::Stream::Latin1</H3></A>


<P>A small, public package for outputting Latin-1 markup.  Its
default auto-escape function is <CODE>LATIN_1</CODE>, which tries to output
the mnemonic entity markup (e.g., <CODE>&amp;ccedil;</CODE>) for ISO-8859-1 characters.


<P>So using HTML::Stream::Latin1 like this:

<FONT SIZE=3 FACE="courier"><PRE>
    use HTML::Stream;
    
    $HTML = new HTML::Stream::Latin1 \*STDOUT;
    output $HTML &quot;\253A right angle is 90\260, \277No?\273\n&quot;;
</PRE></FONT>

<P>Prints this:

<FONT SIZE=3 FACE="courier"><PRE>
    &amp;laquo;A right angle is 90&amp;deg;, &amp;iquest;No?&amp;raquo;
</PRE></FONT>

<P>Instead of what HTML::Stream would print, which is this:

<FONT SIZE=3 FACE="courier"><PRE>
    &amp;#171;A right angle is 90&amp;#176;, &amp;#191;No?&amp;#187;
</PRE></FONT>

<P><B>Warning:</B> a lot of Latin-1 HTML markup is not recognized by older 
browsers (e.g., Netscape 2.0).  Consider using HTML::Stream; it will output 
the decimal entities which currently seem to be more &quot;portable&quot;.


<P><B>Note:</B> using this class &quot;requires&quot; that you have HTML::Entities.



<P><HR>
<A NAME="PERFORMANCE"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> PERFORMANCE</H2></A>


<P>Slower than I'd like.  Both the output() method and the various &quot;tag&quot; 
methods seem to run about 5 times slower than the old 
just-hardcode-the-darn stuff approach.  That is, in general, this:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Approach #1...
    tag  $HTML 'A', HREF=&gt;&quot;$href&quot;;
    tag  $HTML 'IMG', SRC=&gt;&quot;logo.gif&quot;, ALT=&gt;&quot;LOGO&quot;;
    text $HTML $caption;
    tag  $HTML '_A';
    text $HTML $a_lot_of_text;
</PRE></FONT>

<P>And this:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Approach #2...
    output $HTML [A, HREF=&gt;&quot;$href&quot;], 
	         [IMG, SRC=&gt;&quot;logo.gif&quot;, ALT=&gt;&quot;LOGO&quot;],
		 $caption,
		 [_A];
    output $HTML $a_lot_of_text;
</PRE></FONT>

<P>And this:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Approach #3...
    $HTML -&gt; A(HREF=&gt;&quot;$href&quot;)
	  -&gt; IMG(SRC=&gt;&quot;logo.gif&quot;, ALT=&gt;&quot;LOGO&quot;)
	  -&gt; t($caption)
	  -&gt; _A
          -&gt; t($a_lot_of_text);
</PRE></FONT>

<P>Each run about 5x slower than this:

<FONT SIZE=3 FACE="courier"><PRE>
    ### Approach #4...
    print '&lt;A HREF=&quot;', html_escape($href), '&gt;',
          '&lt;IMG SRC=&quot;logo.gif&quot; ALT=&quot;LOGO&quot;&gt;',
  	  html_escape($caption),
          '&lt;/A&gt;';
    print html_escape($a_lot_of_text);
</PRE></FONT>

<P>Of course, I'd much rather use any of first three <I>(especially #3)</I> 
if I had to get something done right in a hurry.  Or did you not notice
the typo in approach #4?  <CODE>;-)</CODE>


<P>(BTW, thanks to Benchmark:: for allowing me to... er... benchmark stuff.)



<P><HR>
<A NAME="VERSION"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> VERSION</H2></A>


<P>$Id: Stream.pm,v 1.54 2001/08/20 20:33:26 eryq Exp $



<P><HR>
<A NAME="CHANGE_LOG"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> CHANGE LOG</H2></A>



<DL>
<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:Version"><A NAME="item:Version_1_54_2001_08_20">Version 1.54   (2001/08/20)</A></A></B></DT>
<DD>
The terms-of-use have been placed in the distribution file &quot;COPYING&quot;.  
Also, small documentation tweaks were made.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:Version"><A NAME="item:Version_1_51_2001_08_16">Version 1.51   (2001/08/16)</A></A></B></DT>
<DD>
No real changes to code; just improved documentation,
and removed HTML::Entities and HTML::Parser from ./etc
at CPAN's request.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:Version"><A NAME="item:Version_1_47_2000_06_10">Version 1.47   (2000/06/10)</A></A></B></DT>
<DD>
No real changes to code; just improved documentation.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:Version"><A NAME="item:Version_1_45_1999_02_09">Version 1.45   (1999/02/09)</A></A></B></DT>
<DD>
Cleanup for Perl 5.005: removed duplicate typeglob assignments.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:Version"><A NAME="item:Version_1_44_1998_01_14">Version 1.44   (1998/01/14)</A></A></B></DT>
<DD>
Win95 install (5.004) now works.
Added SYNOPSIS to POD.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:Version"><A NAME="item:Version_1_41_1998_01_02">Version 1.41   (1998/01/02)</A></A></B></DT>
<DD>
Removed $&amp; for efficiency.
<I>Thanks, Andreas!</I>


<P>Added support for OPTION, and default now puts newlines after SELECT 
and /SELECT.  Also altered &quot;TELEM&quot; syntax to put newline after end-tags 
of list element tags (like /OPTION, /LI, etc.).  In theory, this change
could produce undesireable results for folks who embed lists inside of PRE 
environments... however, that kind of stuff was done in the days before 
TABLEs; also, you can always turn it off if you really need to.
<I>Thanks to John D Groenveld for these patches.</I>


<P>Added text_nbsp().
<I>Thanks to John D Groenveld for the patch.</I>
This method may also be invoked as nbsp_text() as in the original patch, 
but that's sort of a private tip-of-the-hat to the patch author, and the 
synonym may go away in the future.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:Version"><A NAME="item:Version_1_37_1997_02_09">Version 1.37   (1997/02/09)</A></A></B></DT>
<DD>
No real change; just trying to make CPAN.pm happier.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:Version"><A NAME="item:Version_1_32_1997_01_12">Version 1.32   (1997/01/12)</A></A></B></DT>
<DD>
<B>NEW TOOL for generating Perl code which uses HTML::Stream!</B> 
Check your toolkit for <B>html2perlstream</B>.


<P>Added built-in support for escaping 8-bit characters.


<P>Added <CODE>LATIN_1</CODE> auto-escape, which uses HTML::Entities to generate
mnemonic entities.  This is now the default method for HTML::Stream::Latin1.


<P>Added <CODE>auto_format(),</CODE> 
so you can now turn auto-formatting off/on.


<P>Added <CODE>private_tags()</CODE>, 
so it is now possible for HTML streams to each have their own &quot;private&quot;
copy of the %Tags table, for use by <CODE>set_tag()</CODE>.


<P>Added <CODE>set_tag()</CODE>.  The tags tables may now be modified dynamically so 
as to change how formatting is done on-the-fly.  This will hopefully not
compromise the efficiency of the chocolate interface (until now,
the formatting was compiled into the method itself), and <I>will</I> add
greater flexibility for more-complex programs.


<P>Added POD documentation for all subroutines in the public interface.

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:Version"><A NAME="item:Version_1_29_1996_12_10">Version 1.29   (1996/12/10)</A></A></B></DT>
<DD>
Added terminating newline to comment().
<I>Thanks to John D Groenveld for the suggestion and the patch.</I>

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:Version"><A NAME="item:Version_1_27_1996_12_10">Version 1.27   (1996/12/10)</A></A></B></DT>
<DD>
Added built-in HTML::Stream::Latin1, which does a very simple encoding
of all characters above ASCII 127.


<P>Fixed bug in accept_tag(), where 'my' variable was shadowing argument.
<I>Thanks to John D Groenveld for the bug report and the patch.</I>

<P><DT><B><A HREF="#__TOP__"><IMG SRC="icons/itembullet.gif" ALT="Top" BORDER="0"></A> <A NAME="item:Version"><A NAME="item:Version_1_26_1996_09_27">Version 1.26   (1996/09/27)</A></A></B></DT>
<DD>
Start of history.

</DL>



<P><HR>
<A NAME="ACKNOWLEDGEMENTS"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> ACKNOWLEDGEMENTS</H2></A>


<P>Warmest thanks to...

<FONT SIZE=3 FACE="courier"><PRE>
    John Buckman           For suggesting that I write an &quot;html2perlstream&quot;,
                           and inspiring me to look at supporting Latin-1.
    Tony Cebzanov          For suggesting that I write an &quot;html2perlstream&quot;
    John D Groenveld       Bug reports, patches, and suggestions
    B. K. Oxley (binkley)  For suggesting the support of &quot;writing to strings&quot;
                           which became the &quot;printable&quot; interface.
</PRE></FONT>


<P><HR>
<A NAME="AUTHOR"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> AUTHOR</H2></A>


<P>Eryq (<I><FILE><A HREF="mailto:eryq@zeegee.com">eryq@zeegee.com</A></FILE></I>).
President, ZeeGee Software Inc. (<I><FILE><A HREF="http://www.zeegee.com">http://www.zeegee.com</A></FILE></I>).


<P>Go to <I><FILE><A HREF="http://www.zeegee.com">http://www.zeegee.com</A></FILE></I> for the latest downloads
and on-line documentation for this module.  


<P>Enjoy.  Yell if it breaks.

<P><HR>
<ADDRESS><FONT SIZE=-1>
Generated Mon Aug 20 16:33:54 2001 by cvu_pod2html
</FONT></ADDRESS>
</FONT></BODY>
</HTML>