LibreCat / Catmandu-XML

Catmandu modules for working with XML data
https://metacpan.org/module/Catmandu::XML
Other
4 stars 3 forks source link

PerlIO warning #12

Closed jorol closed 10 years ago

jorol commented 10 years ago

Script:

#!/usr/bin/perl

use strict;
use warnings;
use Catmandu::Exporter::XML;

my $exporter = Catmandu::Exporter::XML->new( file => 'out.xml', encoding => 'UTF-8' );
my $state = $exporter->add( [ foo => { bar => 'doz' }, ['&'] ] );

Warning:

Unknown PerlIO layer "UTF" at .../Catmandu/Util.pm line 102.

We should distinguish XML attribute "encoding" (like 'UTF-8') and binmode "encoding" layer (like ':encoding(UTF-8)'). I would prefer the usage of 'UTF-8', 'ISO-8859-1' as argument. The binmode "encoding" layer could be constructed from that. Perhaps this should also be discussed for Catmandu::Exporter.

nichtich commented 10 years ago

UTF-8 is fine but other encoding must also be known to the XML writer to emit character entities of characters not expressible in an encoding. Can be define a list of supported encodings?

jorol commented 10 years ago

'UTF-8' was only an example for my preferred syntax of the argument. Do we need a list? Couldn´t we just check if the encoding is installed and then set the binmode? See https://github.com/jorol/Catmandu-MAB2/blob/devel/lib/MAB2/Writer/Handle.pm

jorol commented 10 years ago

Sorry, I misread your comment... I think the user has to take care, that all characters could be map to other encodings than UTF-8. IO will throw a warning if a character can´t be mapped to the chosen encoding.

nichtich commented 10 years ago

This should better be solved in Catmandu::Exporter instead of overriding its method encoding, file, and fh.

jorol commented 10 years ago

Ok, I will open an issue.