Subject: | use encoding "foo", Filter=>1; does not raise an exception if Filter::Util::Call cannot be used |
Running Encode tests without Filter::Util::Call module available in the system makes t/jperl.t to fail:
$ perl -Iblib/{lib,arch} t/jperl.t
1..15
Unrecognized character \x{fffd}; marked by <-- HERE after our $<-- HERE near column 10 at t/jperl.t line 90.
# Looks like your test exited with 2 before it could output anything.
The test does:
{
use encoding "euc-jp", Filter=>1;
ok(1, "Filter on");
use utf8;
no strict 'vars'; # fools
# doesn't work w/ "my" as of this writing.
# because of buggy strict.pm and utf8.pm
our $人 = 2;
# ^^U+4eba, "human" in CJK ideograph
$人++; # a child is born
*people = \$人;
is ($people, 3, "Filter:utf8 identifier");
no encoding;
ok(1, "Filter off");
}
Obviously the first ok() is there to confirm the "use encoding ..., Filter=>1" pragma succeeded. However the encoding.pm does:
unless ( $arg{Filter} ) {
...
}
else {
defined( ${^ENCODING} ) and undef ${^ENCODING};
# implicitly 'use utf8'
require utf8; # to fetch $utf8::hint_bits;
$^H |= $utf8::hint_bits;
eval {
require Filter::Util::Call;
Filter::Util::Call->import;
filter_add(
sub {
my $status = filter_read();
if ( $status > 0 ) {
$_ = $enc->decode( $_, 1 );
DEBUG and warn $_;
}
$status;
}
);
};
$@ eq '' and DEBUG and warn "Filter installed";
}
The code hides any exception by the eval, so the above-mentioned first test should succeed all the time.
I know the "use encoding" is deprecated, so I do not push for working on this issue or changing behavior. I'm just curious why the encode.pm does pass the exception. (This can be handy if the character set identifier is uknown or the source byte stream is not well-formed for the specified character set.)