Subject: | Audio::Wav::Read |
When the Audio::Wav::Read->read is called with a non-existent or invalid file, it correctly
reports the problem. However, when the object goes out of scope, the following error comes
up:
(in cleanup) Can't call method "close" on an undefined value at
/Library/Perl/5.8.8/Audio/Wav/Read.pm line 92.
Now, looking @ the context for Line 92, I see that it hapens in the destructor:
sub DESTROY {
my $self = shift;
return unless $self;
if ( exists $self -> {'handle'} ) {
$self -> {'handle'} -> close(); #### this is line 92
}
if ( exists $self -> {'tools'} ) {
delete $self -> {'tools'};
}
}
I see that only an 'if (exists $self->{handle})' test is being made; but, in the Audio::Wav::new
constructor the {handle} member is created regardless of whether the open of the file
succeeds or not:
sub new {
my $class = shift;
my $file = shift;
my $tools = shift;
$file =~ s#//#/#g;
my $size = -s $file;
my $handle = new FileHandle "<$file";
my $self = {
'real_size' => $size,
'file' => $file,
'handle' => $handle,
'tools' => $tools,
};
bless $self, $class;
,,,
So, anyway, an easy fix to the problem would be to augment the if (exists ...) test with an if
(defined ...) test:
if (exists $self->{handle} && defined $self->{handle} )
in the destructor; alternatively, the constructor can be modified to not create the {handle}
member unless the creation of the file handle actually succeeds.
regards,
murali.