Skip Menu |

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

Report information
The Basics
Id: 46479
Status: resolved
Priority: 0/
Queue: XML-SAX-Writer

People
Owner: Nobody in particular
Requestors: david.pinkowitz [...] numarasoftware.com
Cc:
AdminCc:

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



Subject: Change prerequisites to include Encode instead of Text::Iconv so Win32 would have easier time installing
On your TODO list for this module, you have the following: - add support for Perl 5.7's Encode module so that we can use it instead of Text::Iconv. Encode is more complete and likely to be better supported overall. This will be done using a pluggable encoder (so that users can provide their own if they want to) and detecter both in Makefile.PL requirements and in the module at runtime. On a Win32 system, there is great difficulty in installing the prerequisite of Text::Iconv. You can see how bad it is by looking at the tester matrix for Win32: http://matrix.cpantesters.org/?dist=Text-Iconv% 201.7;reports=1;os=MSWin32 Encode, on the other hand, does not have this problem and it is part of the Core Perl distribution. I've made a patch that will allow a prerequisite of Encode rather than Text::Iconv. I replaced Text::Iconv completely and made changes to the test scripts as well. If you are willing to do this, this will allow Windows users to have a much easier time of using this module and likely will make creating a PPM easier.
Subject: XMLSaxWriter.diff
--- lib/XML/SAX/Writer.pm Wed Nov 19 18:34:46 2008 +++ lib/XML/SAX/Writer.pm Thu May 28 17:13:54 2009 @@ -8,7 +8,7 @@ use vars qw($VERSION %DEFAULT_ESCAPE %COMMENT_ESCAPE); $VERSION = '0.52'; -use Text::Iconv qw(); +use Encode qw(); use XML::SAX::Exception qw(); use XML::SAX::Writer::XML qw(); use XML::Filter::BufferText qw(); @@ -70,7 +70,7 @@ my $self = shift; if (lc($self->{EncodeFrom}) ne lc($self->{EncodeTo})) { - $self->{Encoder} = Text::Iconv->new($self->{EncodeFrom}, $self->{EncodeTo}); + $self->{Encoder} = XML::SAX::Writer::Encode->new($self->{EncodeFrom}, $self->{EncodeTo}); } else { $self->{Encoder} = XML::SAX::Writer::NullConverter->new; @@ -363,6 +363,29 @@ package XML::SAX::Writer::NullConverter; sub new { return bless [], __PACKAGE__ } sub convert { $_[1] } + + +#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# +#`,`, Encode Converter ,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# +#```````````````````````````````````````````````````````````````````# + +package XML::SAX::Writer::Encode; +sub new { + my $class = shift; + my $self = { + from_enc => shift, + to_enc => shift, + }; + return bless $self, $class; +} +sub convert { + my $self = shift; + my $data = shift; + eval { + Encode::from_to( $data, $self->{from_enc}, $self->{to_enc}, Encode::FB_CROAK ); + }; + return $@ ? undef : $data; +}; 1; --- t/05basic.t Wed Nov 19 18:33:39 2008 +++ t/05basic.t Thu May 28 17:00:22 2009 @@ -6,7 +6,7 @@ ### use strict; -use Test::More tests => 29; +use Test::More tests => 30; BEGIN { use_ok('XML::SAX::Writer'); } # VMS has different names for codepages @@ -45,6 +45,12 @@ # options after initialisation $w1->start_document; isa_ok($w1->{Encoder}, 'XML::SAX::Writer::NullConverter', 'null converter for noop encoding'); +my $w3 = XML::SAX::Writer->new({ + EncodeFrom => $isoL1, + EncodeTo => $isoL2, + })->{Handler}; +$w3->start_document; +isa_ok($w3->{Encoder}, 'XML::SAX::Writer::Encode', 'converter for encoding using Encode'); isa_ok($w1->{NSHelper}, 'XML::NamespaceSupport', 'ns support'); ok(ref($w1->{EscaperRegex}) eq 'Regexp', 'escaper regex'); ok(ref($w1->{NSDecl}) eq 'ARRAY', 'ns stack'); @@ -54,9 +60,6 @@ # different inits (mostly for Consumer DWIM) $w1->{EncodeFrom} = $isoL1; $w1->start_document; -my $iconv_class = 'Text::Iconv'; -$iconv_class .= 'Ptr' if ($Text::Iconv::VERSION >= 1.3); -isa_ok($w1->{Encoder}, $iconv_class, 'iconv converter for real encoding'); $w1->{Output} = 'test_file_for_output'; $w1->start_document; @@ -92,7 +95,14 @@ is($res1, $eq1, 'escaping (default)'); # converting -my $conv = XML::SAX::Writer::NullConverter->new; -my $str = 'TEST'; -my $res = $conv->convert($str); -is($str, $res, 'noop converter'); +my $conv1 = XML::SAX::Writer::NullConverter->new; +my $str1 = 'TEST'; +my $res_1 = $conv1->convert($str1); +is($str1, $res_1, 'noop converter'); + +my $conv2 = XML::SAX::Writer::Encode->new('iso-8859-1', 'utf-8'); +my $str2 = 'Cönvert'; +my $res_2 = $conv2->convert($str2); +use Encode; +Encode::from_to($str2, 'iso-8859-1', 'utf-8'); +is($str2, $res_2, 'Encode converter'); --- Makefile.PL Wed Nov 19 12:24:30 2008 +++ Makefile.PL Thu May 28 15:13:42 2009 @@ -3,7 +3,7 @@ name 'XML-SAX-Writer'; all_from 'lib/XML/SAX/Writer.pm'; -requires 'Text::Iconv' => '1.2'; +requires 'Encode' => '2.12'; requires 'XML::SAX::Exception' => '1.01'; requires 'XML::NamespaceSupport' => '1.00'; requires 'XML::Filter::BufferText' => '1.00'; --- META.yml Wed Nov 19 18:35:07 2008 +++ META.yml Thu May 28 15:14:31 2009 @@ -16,7 +16,7 @@ - inc - t requires: - Text::Iconv: 1.2 + Encode: 2.12 XML::Filter::BufferText: 1.00 XML::NamespaceSupport: 1.00 XML::SAX::Exception: 1.01
Patch applied (as r37) but I'm worried about the loss of 5.6.x support. I have inherited this module and I'm gonna pester the original author for his opinion before I release. Sorry for the delay. -Chris
On Tue Jul 07 23:23:15 2009, PERIGRIN wrote: Show quoted text
> Patch applied (as r37) but I'm worried about the loss of 5.6.x support. > I have inherited this module and I'm gonna pester the original author > for his opinion before I release. Sorry for the delay. > > -Chris
Okay I've spoken with the original author and we've agreed that 5.6.1 support can be deprecated with this release. I will be updating the Makefile.PL tonight and releasing. Thank you for the patch. -Chris