Subject: | Error and Suggestion |
Date: | Wed, 21 Mar 2018 09:57:04 +0000 |
To: | "'bug-net-ebay [...] rt.cpan.org'" <bug-net-ebay [...] rt.cpan.org> |
From: | Puruckherr Jens <jpuruckherr [...] cyberport.de> |
Hi,
we are using Net::eBay for managing our eBay sellings, which works fine.
Unfortunatly I have to copy the module local into our applications to make some modifications to the code which, are not solvable by inheritance.
It would be great if that would not be necessary in the future because these issues are solved in the module:
UTF8:
The used function utf8::upgrade does not work proper in some cases:
perldoc utf8:
" ... Note that this function does not handle arbitrary encodings. Therefore Encode is recommended for the general purposes; see also Encode. ..."
And indeed: using the trademark sign (http://www.fileformat.info/info/unicode/char/2122/index.htm) results in ebay-error 20400: Invalid request encoding. Please use utf-8 encoding and eliminate any non utf-8 encoding in request
content.
Using this (instead of: utf8::upgrade($x))
use Encode;
my $decoded = decode('utf8', $x);
my $encoded = encode('utf8', $decoded);
return $encoded;
works fine in all cases. Unfortunately I cannot overwrite the UTF8 – function by inheritance – the original version is used. May be my perl experience is not sufficient enough?
So, it would be fine, if you make the UTF8 – function overwritable or use Encode directly.
Xml::Simple:
The module provides the ability to force given xml-nodes parsing into arrayrefs instead into hashref – even the node exists only once.
This is very convenient, so you can rely in your app on an fixed response-structure from Net::eBay.
In function submitRequest:
$result = XMLin( $content );
Versus:
$result = XMLin( $content, ForceArray => [ 'Errors', 'OrderArray', 'Order', 'TransactionArray','Transaction', 'ExternalTransaction', 'Dispute', 'ProductSuggestion' ] );
I can overwrite this function by inheritance. But the internal used submitRequestGetText() used the UTF8-function mentioned above and we are back on start 😊
So it would nice, if submitRequest() would accept an optional list with node names to ForceArray. So is no need to overwrite the submitRequest() – function.
But the UTF8-problem is not solved so.
Thanks a lot!
Jens
Here is my inheritaded class for your interest:
package Common::Net::eBay;
use utf8;
use strict;
use warnings;
use base 'Net::eBay';
use XML::Simple;
use Encode;
sub submitRequest {
my ($this) = @_;
# UGLY! calling the parent works not by SUPER::submitRequestGetText
my $content = Net::eBay::submitRequestGetText( @_ );
$this->{last_result_xml} = $content;
$@ = "";
my $result = undef;
eval {
# original
#$result = XMLin( $content );
# my version
$result = XMLin( $content, ForceArray => [ 'Errors', 'OrderArray', 'Order', 'TransactionArray','Transaction', 'ExternalTransaction', 'Dispute', 'ProductSuggestion' ] );
#print "perl result=$result.\n";
};
$this->{_last_text} = $content;
return $result if $result;
warn "Error parsing XML ($@). REF(content) = " . ref( $content ) . " CONTENT=$content\n";
return $content;
}
# gets never used!
sub UTF8 {
my $x = shift @_;
return $x unless defined $x;
#original
#utf8::upgrade($x);
#return $x;
# my version
my $decoded = decode('utf8', $x);
my $encoded = encode('utf8', $decoded);
return $encoded;
}
1;
Message body is not shown because it is too large.