On Fri, 2004-08-20 at 11:03, Geoffrey Young wrote:

> hmph, I'm actually having a difficult time getting ::Extends to do what I
> would think it would do.  consider
> 
>   use Test::MockObject::Extends;
>   my $mock = Test::MockObject::Extends->new('IO::File');
>   $mock->mock('open', sub { print "mocked open\n" });
> 
>   IO::File->open;
> 
> which yields an IO::File::open() error - I would have expected my own
> subroutine to be called instead.  some poking around shows me that if you
> call fake_new() then $class->new->method() works ok, but class methods
> themselves are not overridden, including new(), which is a handy thing to be
> able to override :)
> 
> anyway, is something wrong with the code or my understanding of what
> Test::MockObject::Extends is capable of?

It's your understanding.  You're not mocking the class as a whole. 
You're mocking an instance.  If it helps, think of prototype-based
programming, where you don't inherit from classes, you inherit from
other objects and selectively override or add methods on the new
objects.

If you've never used Self or any advanced JavaScript, ignore that
metaphor.  :)

-- c

Reply via email to