Subject: | safe_encode() fails because encode() not imported to namespace from Encode |
I'm using XML-Twig-3.15 on Solaris 8 (SunOS 5.8), Perl 5.8.0 (5.008), and getting an error when attempting to use the output_filter => 'safe'. Encode is version 1.99.
The error: Undefined subroutine &XML::Twig::encode called at /usr/local/lib/perl5/site_perl/5.8.0/XML/Twig.pm line 3343
It appears that safe_encode() is using encode() from the Encode module as if it's imported into the namespace, but the use statement specifies to only import the :fallback_all group, which doesn't include encode. It seems like the use statement needs to be changed to "use Encode qw( :all)", or to "use Encode qw( :fallback_all encode)".
Or is there something I'm missing?
From Twig.pm:
eval "use Encode qw( :fallback_all)";
sub safe_encode
{ my $str= shift;
if( $] < 5.008)
{ $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
{_XmlUtf8Decode($1)}egs;
}
else
{ $str= encode( ascii => $str, $FB_HTMLCREF); }
return $str;
}
From Encode.pm:
our @EXPORT = qw(
decode decode_utf8 encode encode_utf8
encodings find_encoding clone_encoding
);
our @FB_FLAGS = qw(DIE_ON_ERR WARN_ON_ERR RETURN_ON_ERR LEAVE_SRC
PERLQQ HTMLCREF XMLCREF);
our @FB_CONSTS = qw(FB_DEFAULT FB_CROAK FB_QUIET FB_WARN
FB_PERLQQ FB_HTMLCREF FB_XMLCREF);
our @EXPORT_OK =
(
qw(
_utf8_off _utf8_on define_encoding from_to is_16bit is_8bit
is_utf8 perlio_ok resolve_alias utf8_downgrade utf8_upgrade
),
@FB_FLAGS, @FB_CONSTS,
);
our %EXPORT_TAGS =
(
all => [ @EXPORT, @EXPORT_OK ],
fallbacks => [ @FB_CONSTS ],
fallback_all => [ @FB_CONSTS, @FB_FLAGS ],
);