[SCM] Debian package checker branch, master, updated. 2.5.3-3-gd11c3b9
The following commit has been merged in the master branch:
commit 2af57c692b84a701daa377c93a268f384f53ffc1
Author: Niels Thykier <niels@thykier.net>
Date: Sun Sep 11 09:51:10 2011 +0200
Optimized the XML output a bit
The XML output now uses "self-closing" tags (if possible) and
does not emit attributes with no value.
diff --git a/debian/changelog b/debian/changelog
index 3e2034f..899596f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,9 @@ lintian (2.5.4) UNRELEASED; urgency=low
* lib/Lab.pm:
+ [NT] Updated it to use Lintian::Output::verbosity_level rather
than verbose.
+ * lib/Lintian/Output/XML.pm:
+ + [NT] Use self-closing tags (if possible) and do not write
+ attributes with an empty value.
-- Niels Thykier <niels@thykier.net> Sat, 10 Sep 2011 13:44:01 +0200
diff --git a/lib/Lintian/Output/XML.pm b/lib/Lintian/Output/XML.pm
index d45091a..77823e8 100644
--- a/lib/Lintian/Output/XML.pm
+++ b/lib/Lintian/Output/XML.pm
@@ -47,7 +47,7 @@ sub print_start_pkg {
[ name => $pkg_info->{package} ],
[ architecture => $pkg_info->{arch} ],
[ version => $pkg_info->{version} ]);
- $self->_print_xml_tag('package', \@attrs);
+ print { $self->stdout } $self->_open_xml_tag('package', \@attrs, 0), "\n";
}
sub print_end_pkg {
@@ -66,17 +66,27 @@ sub _print {
print { $stream } $output;
}
-# Print a given XML tag to standard output. Takes the tag, an anonymous array
-# of pairs of attributes and values, and then the contents of the tag.
-sub _print_xml_tag {
- my ($self, $tag, $attrs, $content) = @_;
+sub _open_xml_tag {
+ my ($self, $tag, $attrs, $close) = @_;
my $output = "<$tag";
for my $attr (@$attrs) {
my ($name, $value) = @$attr;
+ # Skip attributes with "empty" values
+ next unless defined $value && $value ne '';
$output .= " $name=" . '"' . $value . '"';
}
+ $output .= ' /' if $close;
$output .= '>';
- if (defined $content) {
+ return $output;
+}
+
+# Print a given XML tag to standard output. Takes the tag, an anonymous array
+# of pairs of attributes and values, and then the contents of the tag.
+sub _print_xml_tag {
+ my ($self, $tag, $attrs, $content) = @_;
+ my $empty = ($content//'') eq '';
+ my $output = $self->_open_xml_tag($tag, $attrs, $empty);
+ if (defined $content && $content ne '') {
$output .= encode_entities($content,"<>&\"'") . "</$tag>";
}
print { $self->stdout } $output, "\n";
--
Debian package checker
Reply to: