summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-10-24 16:01:35 +0200
committerYorhel <git@yorhel.nl>2008-10-24 16:01:35 +0200
commitda8c2ec3805c3086e68ae1f28591929b2dac2bcc (patch)
tree4dfb98bc66979fb7812c43e94e02324cd4823945 /lib
parent33087850cdda3437814be7084114b3601e447604 (diff)
YAWF::XML: Self-closing html tags called indirectly don't need undef
To clarify, before: br; <br> br undef; <br /> tag 'br'; <br> tag 'br', undef; <br /> After this commit: br; <br /> br undef; <br /> tag 'br'; <br> tag 'br', undef; <br />
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Handler/Forms.pm6
-rw-r--r--lib/YAWF/XML.pm18
2 files changed, 17 insertions, 7 deletions
diff --git a/lib/VNDB/Handler/Forms.pm b/lib/VNDB/Handler/Forms.pm
index b39cc44..11a5735 100644
--- a/lib/VNDB/Handler/Forms.pm
+++ b/lib/VNDB/Handler/Forms.pm
@@ -41,10 +41,10 @@ qr/formtest/, sub {
for (1..4) {
label for => 'string'.$_, '#'.$_;
input type => 'text', id => 'string'.$_, name => 'string'.$_,
- value => $frm->{"string$_"}, size => 50, undef;
- br undef;
+ value => $frm->{"string$_"}, size => 50;
+ br;
}
- input type => 'submit', value => 'Submit!', undef;
+ input type => 'submit', value => 'Submit!';
end;
end;
h2 '@rules = ';
diff --git a/lib/YAWF/XML.pm b/lib/YAWF/XML.pm
index 19ca15f..1f6c37d 100644
--- a/lib/YAWF/XML.pm
+++ b/lib/YAWF/XML.pm
@@ -19,7 +19,7 @@ use warnings;
use Exporter;
-our(@htmltags, @htmlexport, @xmlexport);
+our(@htmltags, @htmlexport, @xmlexport, @htmlbool);
BEGIN {
@@ -32,6 +32,9 @@ BEGIN {
legend li Link meta optgroup option param script style title
|;
+ # boolean (self-closing) tags
+ @htmlbool = qw| hr br img input area base frame link param |;
+
# functions to export
@htmlexport = (@htmltags, qw| html lit txt tag end |);
@xmlexport = qw| xml lit txt tag end |;
@@ -39,7 +42,7 @@ BEGIN {
# create the subroutines to map to the html tags
no strict 'refs';
for my $e (@htmltags) {
- *{__PACKAGE__."::$e"} = sub { tag($e, @_) }
+ *{__PACKAGE__."::$e"} = sub { _tag(1, $e, @_) }
}
};
@@ -98,12 +101,16 @@ sub txt {
# 'tagname', id => 'main', '<bar>' <tagname id="main">&lt;bar&gt;</tagname>
# 'tagname', id => 'main', undef <tagname id="main" />
# 'tagname', undef <tagname />
-sub tag {
- (my $name = shift) =~ y/A-Z/a-z/;
+sub _tag {
+ my $indirect = shift; # called as tag() or as generated html function?
+ my $name = shift;
+ $name =~ y/A-Z/a-z/ if $indirect;
my $t = '<'.$name;
$t .= ' '.(shift).'="'.escape(shift).'"' while @_ > 1;
+ push @_, undef if $indirect && !@_ && grep $name eq $_, @htmlbool;
+
if(!@_) {
$t .= '>';
lit $t;
@@ -114,6 +121,9 @@ sub tag {
lit $t.'>'.escape(shift).'</'.$name.'>';
}
}
+sub tag {
+ _tag 0, @_;
+}
# Ends the last opened tag