1 # Copyright 2006 Lennart Borgman, http://OurComments.org/. All rights
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3, or (at your option)
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; see the file COPYING. If not, write to the
16 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 # Boston, MA 02110-1301, USA.
23 use vars qw($AUTOLOAD);
25 sub _make_attributes {
27 return () unless $attr && ref($attr) && ref($attr) eq 'HASH';
29 foreach (keys %{$attr}) {
31 $key=~s/^\-//; # get rid of initial - if present
32 #$key=~tr/a-z_/A-Z-/; # parameters are upper case, use dashes
33 $key=~tr/A-Z_/a-z-/; # parameters are lower case in XHTML
34 push(@att,defined($attr->{$_}) ? qq/$key="$attr->{$_}"/ : qq/$key/);
43 if (ref($_[0]) && ref($_[0]) eq 'HASH') {
44 my(@attr) = html_tags::_make_attributes( '',shift() );
45 $attr = " @attr" if @attr;
47 #return "<$tag_name$attr />" unless @_;
48 return "<$tag_name$attr />" if $part == 1;
49 return "<$tag_name$attr>" if $part == 2;
50 my($tag,$untag) = ("<$tag_name$attr\n>","</$tag_name\n>");
51 my @result = map { "$tag$_$untag" } (ref($_[0]) eq 'ARRAY') ? @{$_[0]} : "@_";
52 return $result[0] if $part == 1;
60 my $sep = ($name =~ s/^\*//);
61 my $lc_name = lc $name;
63 ($lc_name =~ m/^(?:br|hr|input|img)$/ ?
64 "sub $package\:\:$name(;\$\$) { return $caller\:\:_tag('$lc_name',1,\@_); }\n"
66 "sub $package\:\:$name(\$;\$) { return $caller\:\:_tag('$lc_name',0,\@_); }\n"
69 if ($lc_name eq "html") {
70 $code .= "sub $package\:\:start_$name(\$;\$\$)
71 {return $caller\:\:_start_html(\@_);}\n";
72 $code .= "sub $package\:\:end_$name {return $caller\:\:_end_html();}\n";
74 $code .= "sub $package\:\:start_$name(;\$\$)
75 {return $caller\:\:_tag('$lc_name',1,\@_);}\n";
76 $code .= "sub $package\:\:end_$name {'</$lc_name>';}\n";
83 my $head_tags = shift;
84 my $body_attr = shift;
85 # compensate for perl laziness... (will not detect undef sub)
86 $head_tags = $head_tags . _tag("title", 0, $title);
89 _tag("head", 0, $head_tags) .
90 _tag("body", 2, $body_attr);
93 return '</body></html>';
101 my $key = shift @lines; my $value = shift @lines;
102 $header .= "$key: $value\n";
103 $type = $value if $key =~ m/content-type/i;
105 $header .= "Content-type: text/html\n" unless defined $type;
111 $exported{$_}++ for (@_);
113 my $to_eval = "package $caller;\n";
114 for my $name (keys %exported) {
115 die "Will not redefine $caller\:\:$name" if $caller->can($name);
117 if ($name eq "header") {
118 $func = "sub header { html_tags::header(); }";
120 $func = _mk_tag_sub($name, $caller) unless defined $func;
121 $to_eval .= "$func\n";