I have this simple base class (Module):
package XMSP::File;
use parent 'IO::File';
sub new {
my ($self,@args) = @_;
my $object = {};
bless($object,$self);
$object->SUPER::new(@args);
return $object;
}
sub open {
my ($self,@args) = @_;
$self->SUPER::open(@args);
}
sub close {
my ($self,@args) = @_;
$self->SUPER::close(@args);
}
1;
Script:
#!/usr/bin/env perl
use strict;
use warnings;
use XMSP::File;
my $file = XMSP::File->new("< $0");
if (defined $file) {
print "First Ok\n";
$file->close();
}
$file->open("< file");
if (defined $file) {
print "Second Ok\n";
}
On my script I load it using use … I use the ctor (new) to create a new object, etc. but when I close it, it dies with the following error:
First Ok
Not a GLOB reference at /usr/lib/perl/5.10/IO/Handle.pm line 115.
I can’t really figure it out why.
Instead of letting IO::File create the object, you create it, and you create it completely wrong. You didn’t even use the right variable type (hash vs glob). Let IO::File create the object.
Note that this method is completely redundant. I presume you intend to do additional work in it.