package DeepThought;
sub new { bless {}, shift };
sub foo {
my $self = shift;
$self->bar(42);
};
sub bar {
my ($self, $n) = @_;
print "$self says the answer is $n\n";
};
####
use Test::More tests => 2;
isa_ok(my $o = DeepThought->new, 'DeepThought');
{
my $ok;
no warnings;
local *DeepThought::bar = sub { $ok = 1 if $_[1] == 42 };
use warnings;
$o->foo();
ok($ok, 'foo called bar');
};
##
##
package Foo;
use CGI;
sub new {
my $class = shift;
bless {cgi => CGI->new}, $class;
};
##
##
use Test::More tests => 1;
{
my $called = 0;
no warnings;
local *CGI::new = sub { $called = 1 };
use warnings;
my $o = Foo->new;
ok($called, 'Foo->new called CGI->new');
};