Skip Menu |

This queue is for tickets about the XML-TreePP CPAN distribution.

Report information
The Basics
Id: 41986
Status: resolved
Priority: 0/
Queue: XML-TreePP

People
Owner: Nobody in particular
Requestors: SAPER [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: [patch] Prevent a warning when checking Encode version
Hello Yusuke, XML::TreePP is used at work, and recently I was asked to take a look at it because of unwanted warnings, which fill the logs. The problem lies in the fact that we mostly use Debian sarge, which is shipped with Perl 5.8.4, which includes Encode 1.99_01. When the method encode_from_to() is called, it generates this warning: Argument "1.99_01" isn't numeric in numeric lt (<) at .../XML/TreePP.pm line 882 I proposed a patch for the calling to silence the warning. Here is a similar patch, now for XML::TreePP itself. Also, depending on how often this method is called (I don't maintain the code which makes use of XML::TreePP), I'd suggest to move $check at package level so it's evaluated only once. A even better optimisation (but harder to do) would be to inline all the small parts in this method so that when it is called, only the code for the current versions of Perl and Encode are executed. Thanks in advance -- Close the world, txEn eht nepO.
Subject: XML-TreePP-0.36-version-check.diff
diff -ru XML-TreePP-0.36-orig/lib/XML/TreePP.pm XML-TreePP-0.36-new/lib/XML/TreePP.pm --- XML-TreePP-0.36-orig/lib/XML/TreePP.pm 2008-10-26 07:17:10.000000000 +0100 +++ XML-TreePP-0.36-new/lib/XML/TreePP.pm 2008-12-25 20:07:15.000000000 +0100 @@ -1095,7 +1095,11 @@ if ( $] >= 5.008 ) { &load_encode(); - my $check = ( $Encode::VERSION < 2.13 ) ? 0x400 : Encode::FB_XMLCREF(); + my $check = do { + local $SIG{__WARN__} = sub {}; + $Encode::VERSION < 2.13 ? 0x400 : Encode::FB_XMLCREF(); + }; + if ( $] >= 5.008001 && utf8::is_utf8( $$txtref ) ) { if ( $to =~ /^utf-?8$/i ) { # skip
RT-Send-CC: xml-treepp [...] yahoogroups.com
Thanks for your patch. - my $check = ( $Encode::VERSION < 2.13 ) ? 0x400 : Encode::FB_XMLCREF(); + my $ver = ( $Encode::VERSION =~ /^([\d\.]+)/ )[0]; + my $check = ( $ver < 2.13 ) ? 0x400 : Encode::FB_XMLCREF(); could be fine (but not tested well). The next release will be updated with this. ---- Yusuke Kawasaki On 2008/12/27 12:17:08, SAPER wrote: Show quoted text
> Hello Yusuke, > > XML::TreePP is used at work, and recently I was asked to take > a look at it because of unwanted warnings, which fill the logs. > The problem lies in the fact that we mostly use Debian sarge, > which is shipped with Perl 5.8.4, which includes Encode 1.99_01. > When the method encode_from_to() is called, it generates this > warning: Argument "1.99_01" isn't numeric in numeric lt (<) > at .../XML/TreePP.pm line 882 > > I proposed a patch for the calling to silence the warning. > Here is a similar patch, now for XML::TreePP itself. > > Also, depending on how often this method is called (I don't > maintain the code which makes use of XML::TreePP), I'd suggest > to move $check at package level so it's evaluated only once. > A even better optimisation (but harder to do) would be to inline > all the small parts in this method so that when it is called, > only the code for the current versions of Perl and Encode are > executed. > > > Thanks in advance
FYI, about the reason for ( $ver < 2.13 ), see also: http://kawa.at.webry.info/200605/article_11.html Dan-san suggested to use below: my $check = ( $Encode::VERSION < 2.13 ) ? Encode::FB_XMLCREF() : Encode::XMLCREF(); http://blog.livedoor.jp/dankogai/archives/50502791.html Both articles are written in Japanese however!
Subject: Re: [rt.cpan.org #41986] [patch] Prevent a warning when checking Encode version
Date: Thu, 15 Jan 2009 21:58:44 +0100
To: bug-XML-TreePP [...] rt.cpan.org
From: Sébastien Aperghis-Tramoni <SAPER [...] cpan.org>
Yusuke Kawasaki wrote via RT: Show quoted text
> Thanks for your patch. > > - my $check = ( $Encode::VERSION < 2.13 ) ? 0x400 : > Encode::FB_XMLCREF(); > + my $ver = ( $Encode::VERSION =~ /^([\d\.]+)/ )[0]; > + my $check = ( $ver < 2.13 ) ? 0x400 : Encode::FB_XMLCREF(); > > could be fine (but not tested well). > The next release will be updated with this.
Thanks Show quoted text
> FYI, about the reason for ( $ver < 2.13 ), see also: > http://kawa.at.webry.info/200605/article_11.html > > Dan-san suggested to use below: > my $check = ( $Encode::VERSION < 2.13 ) ? Encode::FB_XMLCREF() : > Encode::XMLCREF(); > http://blog.livedoor.jp/dankogai/archives/50502791.html > > Both articles are written in Japanese however!
I think I understand the main part of the problem (with the help of the fish). I was guessing that it wasn't a gratuitous check, given I have similar tests in some of my code that has to deal with old modules or old Perls. -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO.