On Tue, 2011-05-17 at 07:27 -0700, Al wrote:
> For me I've found the best solution is to leave Encode.pm 
> alone and redefine the offending subroutine within my processing script. I 
> paste this in at the bottom of every script:

I always feel a little funny about promoting my own modules, but this
sounds like a perfect case for LocalOverride
( http://search.cpan.org/~dsheroh/LocalOverride-1.000/lib/LocalOverride.pm )

Create a Local/Encode.pm module containing:

--- cut here ---
package Encode;      # Note: NOT Local::Encode!
use Encode::Alias;

no warnings 'redefine';

sub decode($$;$)
{
    my ($name,$octets,$check) = @_;
    my $altstring = $octets;
    return undef unless defined $octets;
    $octets .= '' if ref $octets;
    $check ||=0;
    my $enc = find_encoding($name);
    unless(defined $enc){
       require Carp;
       Carp::croak("Unknown encoding '$name'");
    }
    my $string;
    eval { $string = $enc->decode($octets,$check); };
    $_[1] = $octets if $check and !($check & LEAVE_SRC());
    if ($@) {
       return $altstring;
    } else {
       return $string;
    }
}
--- cut here ---

and add the line "use LocalOverride;" to your main script and
LocalOverride should take it from there, at least in theory.

Reply via email to