|Subject:||Object only accepts unicode strings|
Handling strings is correctly is difficult in Perl. Sometimes we need to know the internals. The official rule is: users should not need to know whether a string has the utf8 flag on or not. When I do this: my $latin1 = chr 230; my $gc = Unicode::GCString->new($latin1); I get the error _new: Unicode string must be given. at /home/perl/5.16.2/lib/site_perl/5.16.2/x86_64-linux/Unicode/GCString.pm line 46. So: this does not follow Perl's rule of "it just works". I can do my $latin1 = chr 230; my $gc = Unicode::GCString->new(decode latin1 => $latin1); Now, I do not get the error. Great. So, for correctly calling your object in any circumstance, I need to call: my $gc = Unicode::GCString->new(is_utf8($s) ? $s : decode(latin1 => $s)); Which is inconvenient. Please make your new() internally this smart. "man perlunicode" says that non-utf8 strings are to be interpreted as in latin1.