1HTML::AsSubs(3) User Contributed Perl Documentation HTML::AsSubs(3)
2
3
4
6 HTML::AsSubs - functions that construct a HTML syntax tree
7
9 This document describes version 5.07 of HTML::AsSubs, released August
10 31, 2017 as part of HTML-Tree.
11
13 use HTML::AsSubs;
14 $h = body(
15 h1("This is the heading"),
16 p("This is the first paragraph which contains a ",
17 a({href=>'link.html'}, "link"),
18 " and an ",
19 img({src=>'img.gif', alt=>'image'}),
20 "."
21 ),
22 );
23 print $h->as_HTML;
24
26 This module exports functions that can be used to construct various
27 HTML elements. The functions are named after the tags of the
28 corresponding HTML element and are all written in lower case. If the
29 first argument is a hash reference then it will be used to initialize
30 the attributes of this element. The remaining arguments are regarded as
31 content.
32
33 For a similar idea (i.e., it's another case where the syntax tree of
34 the Perl source mirrors the syntax tree of the HTML produced), see
35 HTML::Element's "new_from_lol" method.
36
37 For what I now think is a cleaner implementation of this same idea, see
38 the excellent module "XML::Generator", which is what I suggest for
39 actual real-life use. (I suggest this over "HTML::AsSubs" and over
40 "CGI.pm"'s HTML-making functions.)
41
43 This module was inspired by the following message:
44
45 Date: Tue, 4 Oct 1994 16:11:30 +0100
46 Subject: Wow! I have a large lightbulb above my head!
47
48 Take a moment to consider these lines:
49
50 %OVERLOAD=( '""' => sub { join("", @{$_[0]}) } );
51
52 sub html { my($type)=shift; bless ["<$type>", @_, "</$type>"]; }
53
54 :-) I *love* Perl 5! Thankyou Larry and Ilya.
55
56 Regards,
57 Tim Bunce.
58
59 p.s. If you didn't get it, think about recursive data types: html(html())
60 p.p.s. I'll turn this into a much more practical example in a day or two.
61 p.p.p.s. It's a pity that overloads are not inherited. Is this a bug?
62
64 The exported link() function overrides the builtin link() function.
65 The exported tr() function must be called using &tr(...) syntax because
66 it clashes with the builtin tr/../../ operator.
67
69 HTML::Element, XML::Generator
70
71 html head title base link meta isindex nextid script style body h1 h2 h3 h4
72 h5 h6 p pre div blockquote a img br hr ol ul dir menu li dl dt dd dfn
73 cite code em kbd samp strong var address span b i u tt center font big
74 small strike sub sup table tr td th caption form input select option
75 textarea object applet param map area frame frameset noframe
76 A bunch of methods for creating tags.
77
79 _elem()
80 The _elem() function is wrapped by all the html 'tag' functions. It
81 takes a tag-name, optional hashref of attributes and a list of content
82 as parameters.
83
85 Current maintainers:
86
87 • Christopher J. Madsen "<perl AT cjmweb.net>"
88
89 • Jeff Fearn "<jfearn AT cpan.org>"
90
91 Original HTML-Tree author:
92
93 • Gisle Aas
94
95 Former maintainers:
96
97 • Sean M. Burke
98
99 • Andy Lester
100
101 • Pete Krawczyk "<petek AT cpan.org>"
102
103 You can follow or contribute to HTML-Tree's development at
104 <https://github.com/kentfredric/HTML-Tree>.
105
107 Copyright 1995-1998 Gisle Aas, 1999-2004 Sean M. Burke, 2005 Andy
108 Lester, 2006 Pete Krawczyk, 2010 Jeff Fearn, 2012 Christopher J.
109 Madsen.
110
111 This library is free software; you can redistribute it and/or modify it
112 under the same terms as Perl itself.
113
114 The programs in this library are distributed in the hope that they will
115 be useful, but without any warranty; without even the implied warranty
116 of merchantability or fitness for a particular purpose.
117
118
119
120perl v5.32.1 2021-01-27 HTML::AsSubs(3)