testing

Christopher Jones c.jones at ucl.ac.uk
Mon Nov 3 16:38:27 GMT 2008


On 3 Nov 2008, at 13:57, Jonathan Stowe wrote:

> 2008/11/3 Christopher Jones <c.jones at ucl.ac.uk>:
>> Should you be able to create and call methods from a package in a  
>> test
>> script? i.e Should something like this work? (i.e.i.e. it doesn't  
>> seem to
>> for me right now).
>>
>>
>> #!/usr/bin/perl -w
>> use strict;
>>
>> use Test::More tests => 2;
>>
>> BEGIN {
>>       use_ok('My::Module');    # contains a package called 'my_mod'
>> };
>> test 'object init' => sub {
>>       ok(my $object = my_test_mod->new(),'init');
>> };
>>
>> { package my_test_mod;
>>       our @ISA = qw( my_mod );
>> }
>>
>
> It is highly un-recommended to have have a module file which contains
> a differently named package. That is to say your  "$LIB/My/Module.pm"
> should contain the package "My::Module".



Forgive me for my ignorance.... I learnt all my ooPerl from "Learning  
Perl Objects, References and Modules", followed by browsing through  
"Object Oriented Perl" by Damian Conway, and have no idea which (if  
either) is considered a good introduction. But assuming Randal and Tom  
know something about ooPerl, they have no problem with a module "$LIB/ 
My/Module.pm" like this;

package My::Module;
{ package my_mod;
	sub new {
		# etc
	}
}
{ package my_other_mod;
	our @ISA = qw( my_mod );
	sub foo {
		# more etc
	}
}
1;


Which is the kind of structure I was referring to in the test script  
example.


Chris.





More information about the london.pm mailing list