R
Ratty
I'm using the MARC::Batch module. It refuses to process records with
character encoding issues. It dies with a warning about line 166 in
Encode.pm. I can use eval to make it skip bad records instead but I
don't want that either. I want it to do the best it can. What I need
to do is modify Encode::decode so it does not die when it can't decode
a string. This works if I add an eval to Encode.pm sitting in my perl/
lib directory. But I don't want to do it this way. I want everything
restricted to my one calling program. I seem to remember doing
something similar years ago by simply copying the subroutine, with
package name, into my program and my program would use that instead.
But it doesn't work for me this time. No errors, it simply ignores it.
Perhaps because I'm not calling the module directly this time, but
rather it is being called somewhere in the bowels of MARC::Record,
which I'm also not calling directly.
use MARC::Batch;
## Programming here
## Attempt to override
sub Encode::decode($$;$)
{
my ($name,$octets,$check) = @_;
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'");
}
## Add eval heres
my $string;
eval { $string = $enc->decode($octets,$check); };
$_[1] = $octets if $check and !($check & LEAVE_SRC());
return $string;
}
What's the most elegant way to redefine somebody else's subroutine?
BTW, I also tried:
{
local *Encode::decode = \&myDecode;
}
Doesn't work either
character encoding issues. It dies with a warning about line 166 in
Encode.pm. I can use eval to make it skip bad records instead but I
don't want that either. I want it to do the best it can. What I need
to do is modify Encode::decode so it does not die when it can't decode
a string. This works if I add an eval to Encode.pm sitting in my perl/
lib directory. But I don't want to do it this way. I want everything
restricted to my one calling program. I seem to remember doing
something similar years ago by simply copying the subroutine, with
package name, into my program and my program would use that instead.
But it doesn't work for me this time. No errors, it simply ignores it.
Perhaps because I'm not calling the module directly this time, but
rather it is being called somewhere in the bowels of MARC::Record,
which I'm also not calling directly.
use MARC::Batch;
## Programming here
## Attempt to override
sub Encode::decode($$;$)
{
my ($name,$octets,$check) = @_;
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'");
}
## Add eval heres
my $string;
eval { $string = $enc->decode($octets,$check); };
$_[1] = $octets if $check and !($check & LEAVE_SRC());
return $string;
}
What's the most elegant way to redefine somebody else's subroutine?
BTW, I also tried:
{
local *Encode::decode = \&myDecode;
}
Doesn't work either