1HTML::AsSubs(3)       User Contributed Perl Documentation      HTML::AsSubs(3)
2
3
4

NAME

6       HTML::AsSubs - functions that construct a HTML syntax tree
7

SYNOPSIS

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

DESCRIPTION

22       This module exports functions that can be used to construct various
23       HTML elements. The functions are named after the tags of the
24       correponding HTML element and are all written in lower case. If the
25       first argument is a hash reference then it will be used to initialize
26       the 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

ACKNOWLEDGEMENT

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

BUGS

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

SEE ALSO

65       HTML::Element, XML::Generator
66

Private Functions

68   _elem()
69       The _elem() function is wrapped by all the html 'tag' functions. It
70       takes a tag-name, optional hashref of attributes and a list of content
71       as parameters.
72
73
74
75perl v5.10.1                      2006-08-04                   HTML::AsSubs(3)
Impressum