#!/usr/bin/perl use strict; use warnings; use FileHandle; use File::Tee qw(tee); use Test::MockObject::Extends; tee('STDOUT', '>>', 'stdout.txt'); my $mock= Test::MockObject::Extends->new(FileHandle->new); $mock->set_false( 'print' ); $mock->mock('FileHandle'); my $a = FileHandle->new; die "could not open" unless $a->open('>K'); die "I expect to die here" unless print {$a;} "hello"; die "I expect to be dead before we get to this point" unless $a->print("hello"); print $a;