testing

Andy Armstrong andy at hexten.net
Mon Nov 3 14:31:16 GMT 2008


On 3 Nov 2008, at 14:08, Dominic Thoreau wrote:
> Scope is always useful once you understand it - but can be nasty  
> when you don't.

Exactly!

> 'Course I could be wrong.....

Yup :)

I don't know where the 'test' subroutine comes from but I'm assuming
it's something like this:

     sub test($&) {
       my ( $msg, $sub ) = @_;
       $sub->();
     }

Your main problem is that the @ISA assignment in my_test_mod isn't
executed until after you attempt to instantiate my_test_mod. This works:

     #!/usr/bin/perl -w
     use strict;

     use Test::More tests => 2;

     sub test($&) {
       my ( $msg, $sub ) = @_;
       $sub->();
     }

     BEGIN {
       use_ok( 'My::Module' );    # contains a package called 'my_mod'
     }

     package my_test_mod;
     our @ISA = qw( my_mod );

     package main;

     test 'object init' => sub {
       ok( my $object = my_test_mod->new(), 'init' );
     };


As has already been said it's a good idea to name files according to the
main package that they provide. It's not mandatory but it's assumed by
lots of extant code.

-- 
Andy Armstrong, Hexten



More information about the london.pm mailing list