Reputation: 4580
I need to write my own Test module (TestOwn) that use the Test::More module. So the code of TestOwn.pm is something like:
package TestOwn;
use Test::More;
1;
Then i try to use the package in one of my test file (test01.t);
use lib -e 't' ? 't' : 'test';
use TestOwn;
....
done_testing();
But when the test is run i have the error:
t/test01.t .. Undefined subroutine &main::done_testing
So it seems that functions in Test::More are not imported in my test file by the use TestOwn command.
Upvotes: 0
Views: 120
Reputation:
By default, nothing in your module is exported into the code that calls it. This is by design, as exporting is a rather dangerous activity that could result in name clashes.
You have to define what things to export by default (and you can also give the user of the module some control of this behavior). See Exporter.
You could export the methods of another module, but this isn't really a good idea. What if someone uses your module and Test::More
? A better option would be to create your own wrappers around the Test::More
functions that you think are needed, then export those. But you should limit exporting as much as possible. There are better alternatives, such as using an OO design with methods. See the above documentation for more discussion of this.
The calling code can also access stuff that is not exported by using Module::function()
.
Upvotes: 2