On Dec 14, Michael Schwern wrote:
> Constructors fail often enough that I felt it worthwhile to write a
> test function for them.
> 
> You could leave off the test entirely and just trust that you use $foo
> later on down in the test and it'll explode there, but its better to
> put the point of failure as close to where the bug is as possible.
> And you get no diagnostic information (see below).
> 
> 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.

    Or ok(UNIVERSAL::isa(Foo->new, 'Foo'));

    - Kurt

Reply via email to