Subject: | Upgraded perl-string handling is surprising ( the API does not warn, and the docs do not discuss it ) |
Consider the output of the following simple one-liner:
perl -e '
use warnings;
use strict;
use Math::GMPz;
my $gmpz = Math::GMPz::Rmpz_init2_nobless(8);
my $byte = "\xff";
for my $up ( 0, 1, 0, 1, 0 ) {
$up
? utf8::upgrade($byte)
: utf8::downgrade($byte)
;
Math::GMPz::Rmpz_import(
$gmpz,
length( $byte ),
1, 1, 0, 0,
$byte,
);
warn Math::GMPz::Rmpz_get_str( $gmpz, 16 );
}
'
My main surprise came from the fact that the documentation did not discuss this eventuality at all, so I assumed I do not need to guard against it. Then weeks later one of my inputs suffered a change causing implicit upgrades, and nothing made sense afterwards.
I am not sure whether the fix should be in doc, in code, or both. I am only reporting the confusing behavior.