#!perl use strict; use warnings; use FileHandle; use Test::MockObject::Extends; my $mock= Test::MockObject::Extends->new(FileHandle->new); $mock->set_false( 'print' ); $mock->fake_new('FileHandle'); my $a = FileHandle->new; $a->open(">K") or die "could not open"; print {$a} "hello" or die "I expect to die here"; $a->print("hello") or die "I expect to be dead before we get to this point"; #### #!perl use strict; use warnings; package A; sub new { my $class = shift; return bless {}, $class; } sub whoami { my $self = shift; return "I am an A.\n"; } sub sayhi { my $self = shift; return "Hi!\n"; } package main; my $a = A->new; print $a->whoami; print $a->sayhi; use Test::MockObject::Extends; $a = Test::MockObject::Extends->new($a); $a->mock('sayhi', sub {return "Nope. Won't say 'Hi!'.\n";}); my $a2 = A->new; print $a2->whoami; print $a2->sayhi; $a->fake_new('A'); my $a3 = A->new; print $a3->whoami; print $a3->sayhi;