From bd65b9ed515959e67db9cb1b198526f9ac2dfca5 Mon Sep 17 00:00:00 2001 From: Johann Rolschewski Date: Sat, 5 Apr 2014 13:41:33 +0200 Subject: [PATCH] XML parser should ignore PerlIO layers --- lib/MAB2/Parser/XML.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/MAB2/Parser/XML.pm b/lib/MAB2/Parser/XML.pm index 2413838..d00c6cb 100644 --- a/lib/MAB2/Parser/XML.pm +++ b/lib/MAB2/Parser/XML.pm @@ -60,12 +60,13 @@ sub new { # check for file or filehandle my $ishandle = eval { fileno($input); }; if ( !$@ && defined $ishandle ) { + binmode $input; # drop all PerlIO layers, as required by libxml2 my $reader = XML::LibXML::Reader->new( IO => $input ) or croak "cannot read from filehandle $input\n"; $self->{filename} = scalar $input; $self->{xml_reader} = $reader; } - elsif ( -e $input ) { + elsif ( defined $input && $input !~ /\n/ && -e $input ) { my $reader = XML::LibXML::Reader->new( location => $input ) or croak "cannot read from file $input\n"; $self->{filename} = $input;