in reply to Making open fail
IO::File is only involved if you use HANDLE->print(...), not for print(HANDLE ...), much less before the handle is even created by open. It's not relevant here.
Contrary to what you said, subs works fine.
use strict; use warnings; use subs qw( open ); use Errno qw( EPIPE ); sub open { $! = EPIPE; return 0; } open(my $fh, '<', \my $buf) or die("open: $!\n");
open: Broken pipe
Update: You probably want to test a module without changing it, so your code would look more like the following:
package ModuleToTest; sub f { open(my $fh, '<', \my $buf) or die("open: $!\n"); } 1;
use Test::More tests => 1; { package ModuleToTest; use subs qw( open ); use Errno qw( EPIPE ); sub open { $! = EPIPE; return 0; } } use Module; ok( !eval { Module->f(); 1 } );
1..1 ok 1
|
|---|