Subject: | XML::LibXML::Node objects emit warning in bool operations, when XML::Declare is used |
Due to overloading of stringification in XML::LibXML::Node, warning is
emitted every time, when object of Node class is used in bool context.
Here is a test and a patch for it.
Subject: | kill-bool-warning.diff |
--- lib/XML/Declare.pm 2011-03-15 11:42:17.059159000 +0300
+++ lib/XML/Declare.pm.new2 2011-03-15 11:42:45.025158713 +0300
@@ -1,7 +1,10 @@
package # hide
XML::LibXML::Node;
- use overload '""' => 'toString',
- fallback => 1;
+ use overload (
+ q{""} => 'toString',
+ q{bool} => sub { 1 },
+ fallback => 1,
+ );
package XML::Declare;
Subject: | 02-bool-overloaded.t |
use strict;
use warnings;
use Test::More tests => 1; # last test to print
use XML::Declare;
my $doc = doc {
element feed => sub {
attr xmlns => 'http://www.w3.org/2005/Atom';
comment "generated using XML::Declare v$XML::Declare::VERSION";
for (1..3) {
element entry => sub {
element title => 'Title', type => 'text';
element content => sub {
attr type => 'text';
cdata 'Desc';
};
element published => '123123-1231-123-123';
element author => sub {
element name => 'Mons';
}
};
}
};
} '1.0', 'utf-8';
my $entries = $doc->getElementsByTagName('entry');
my $entry = $entries->shift;
my $warning;
{
local $SIG{__WARN__} = sub { $warning = shift; };
# Trying to emit a warning
if ( $entry ) {
}
}
ok(!$warning, 'No warnings are emitted in bool context');