... my $obj = Widget::File->new(filename => $testfile, # a real file otherstuff => ...); my $dirh = IO::File->new('/', O_RDONLY); # reading a dirhandle forces a read() failure on Linux $obj->{fh} = $dirh; # invoke a method that calls read() internally eval { $obj->header(); # read()ing from a dirhandle forces an EISDIR error }; like($@, qr(Error in reading file header - Is a directory at ));