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 use HTML::AsSubs;
10 $h = body(
11 h1("This is the heading"),
12 p("This is the first paragraph which contains a ",
13 a({href=>'link.html'}, "link"),
14 " and an ",
15 img({src=>'img.gif', alt=>'image'}),
16 "."
17 ),
18 );
19 print $h->as_HTML;
20
22 This module exports functions that can be used to construct various
23 HTML elements. The functions are named after the tags of the correpond‐
24 ing HTML element and are all written in lower case. If the first argu‐
25 ment is a hash reference then it will be used to initialize the
26 attributes of this element. The remaining arguments are regarded as
27 content.
28
29 For a similar idea (i.e., it's another case where the syntax tree of
30 the Perl source mirrors the syntax tree of the HTML produced), see
31 HTML::Element's "new_from_lol" method.
32
33 For what I now think is a cleaner implementation of this same idea, see
34 the excellent module "XML::Generator", which is what I suggest for
35 actual real-life use. (I suggest this over "HTML::AsSubs" and over
36 "CGI.pm"'s HTML-making functions.)
37
39 This module was inspired by the following message:
40
41 Date: Tue, 4 Oct 1994 16:11:30 +0100
42 Subject: Wow! I have a large lightbulb above my head!
43
44 Take a moment to consider these lines:
45
46 %OVERLOAD=( '""' => sub { join("", @{$_[0]}) } );
47
48 sub html { my($type)=shift; bless ["<$type>", @_, "</$type>"]; }
49
50 :-) I *love* Perl 5! Thankyou Larry and Ilya.
51
52 Regards,
53 Tim Bunce.
54
55 p.s. If you didn't get it, think about recursive data types: html(html())
56 p.p.s. I'll turn this into a much more practical example in a day or two.
57 p.p.p.s. It's a pity that overloads are not inherited. Is this a bug?
58
60 The exported link() function overrides the builtin link() function.
61 The exported tr() function must be called using &tr(...) syntax because
62 it clashes with the builtin tr/../../ operator.
63
65 HTML::Element, XML::Generator
66
68 _elem()
69
70 The _elem() function is wrapped by all the html 'tag' functions. It
71 takes a tag-name, optional hashref of attributes and a list of content
72 as parameters.
73
74
75
76perl v5.8.8 2006-08-04 HTML::AsSubs(3)