File: file_consumer_encoding.patch

package info (click to toggle)
libxml-sax-writer-perl 0.50-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 144 kB
  • ctags: 66
  • sloc: perl: 494; makefile: 42
file content (30 lines) | stat: -rw-r--r-- 1,053 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Author: Florian Ragwitz <rafl@debian.org>
Description: Add '>:encoding(EncodeTo)' line discipline to FileConsumer to defeat 
perl's automatic charset conversion.
--- libxml-sax-writer-perl.orig/Writer.pm
+++ libxml-sax-writer-perl/Writer.pm
@@ -331,7 +331,10 @@
 # new
 #-------------------------------------------------------------------#
 sub new {
-    my ( $proto, $file ) = ( shift, shift );
+    my ( $proto, $file, $opt ) = @_;
+    my $enc_to = (defined $opt and ref $opt eq 'HASH'
+                  and defined $opt->{EncodeTo}) ? $opt->{EncodeTo}
+                                                : 'utf-8';
 
     XML::SAX::Writer::Exception->throw(
         Message => "No filename provided to " . ref( $proto || $proto )
@@ -339,9 +342,10 @@
 
     local *XFH;
 
-    open XFH, ">$file" or XML::SAX::Writer::Exception->throw(
+    open XFH, ">:encoding($enc_to)", $file
+      or XML::SAX::Writer::Exception->throw(
         Message => "Error opening file $file: $!"
-    );
+      );
 
     return $proto->SUPER::new( *{XFH}{IO}, @_ );
 }