On Sun, Dec 16, 2001 at 02:41:31PM +0000, Piers Cawley wrote:
> Nothing wrong with an adaptor/factory returning something that isn't a
> Foo, so long as it has the same interface.

That's why its isa_ok() and not ref_ok().

On the off chance Foo->new is supposed to return something that bears
no relation to Foo at all, then just don't use isa_ok.  Or, check that
its that other thing:

    my $foo = Foo->new;
    isa_ok( $foo, 'Bar' );


> > The equivalent code without isa_ok() would be:
> >
> >     my $foo = Foo->new;
> >     ok( $foo->isa('Foo') );
> >
> > except should $foo be unblessed or undef that will explode.  You have
> > to start doing things like:
> >
> >     my $foo = Foo->new;
> >     ok( defined $foo && $foo->isa('Foo') );
> >
> > which rapidly gets tiresome.  It also provides you little information
> > about what value $foo held that caused it to fail.
> 
> What's wrong with 
> 
>     ok ( eval { $foo->isa('Foo') } );
>
> or even:
> 
>     ok (eval { ref($foo) && $foo->isa('Foo') });

As Kurt already pointed out, you can do:

    ok( UNIVERSAL::isa($foo, 'Foo') );

but if it fails you have no idea what $foo was.


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl Quality Assurance      <[EMAIL PROTECTED]>         Kwalitee Is Job One
First day in Prison
Back behind the shower door
Adhesive applied
        -- ignatz

Reply via email to