package Object::Test; use base qw(Test::Class); use Test::More; # run $code while pretending that __PACKAGE__ ISA $class sub _do_as(&$) { my ($code, $class) = @_; { # we have to make sure the package hash exists # for the method dispatch to work no strict 'refs'; *{"$class\::"}{HASH} }; local @Object::Test::ISA = ($class, @Object::Test::ISA); $code->(); }; sub setup : Test(setup) { my $self = shift; _do_as { $self->{object} = Object->new(logger => $self) } 'Logger'; }; sub test_show_answer : Test(3) { my $self = shift; _do_as { $self->{object}->log("hello", "there") } 'Logger'; }; sub log { my $self = shift; is($_[0], $self->{object}, 'passed object to logger'); is($_[1], "hello", 'passed arg1'); is($_[2], "there", 'passed arg2'); };