tags:

views:

184

answers:

4

I have a .pm file in my current directory /t, and I inserted this line of code:

use lib qw(.);

Then I inserted this line of code

use TestUtil.pm;

where TestUtil.pm is in the current directory, but I keep getting this error:

Can't locate TestUtil.pm in @INC (@INC contains: . ........ ( Note that @INC contains the current directory)

TestUtil.pm:

package TestUtil;

use strict; use warnings;

BEGIN { use Exporter (); use vars qw( $VERSION @ISA @EXPORT );

# Set the version for version checking
$VERSION = 1.00; @ISA = qw( Exporter ); @EXPORT = qw(_a ); }

use vars qw( $VERSION @ISA @EXPORT );

sub _a { return 1; }

test_XXX.t:

use lib qw(.); use strict; use warnings;

use TestUtil;

What am I doing wrong?

+2  A: 

Try removing the .pm from the module name in the "use ..." statement.

cberg
Oh sorry I originally did not have the .pm in it.Also I tried require "./TestUtil.pm"; which did not work (and yes, this one has a .pm in it)
Kys
A: 

Have you declared the TestUtil.pm as a TestUtil module?

# in your TestUtil module...
package TestUtil;

EDIT:

Is your Perl module (TestUtil.pm) returning a status? Try adding this to the end of the TestUtil.pm file:

1;
bedwyr
So I have:# in my TestUtil.pm file...package TestUtil;use strict;use warnings;sub a{}# in my test_XXX.t file...use lib qw(.);use TestUtil;
Kys
Can you paste the code in your original question? It's hard to think of potential solutions w/out more information.
bedwyr
A: 

In TestUtil.pm


package TestUtil;

use strict; use warnings;

BEGIN { use Exporter (); use vars qw( $VERSION @ISA @EXPORT );

# Set the version for version checking
$VERSION = 1.00; @ISA = qw( Exporter ); @EXPORT = qw(_a ); }

use vars qw( $VERSION @ISA @EXPORT );

sub _a { return 1; }


In test_XXX.t


use lib qw(.); use strict; use warnings;

use TestUtil;


Kys
Just an etiquette-thing: it's best to post any updates to your question in the original source of the question. This way your responses don't get lost when other potential solutions are up-voted.
bedwyr
Sorry. The character limit did not allow me to make it as a comment.
Kys
See my original post -- one more quick idea. This worked for me when I copied your code.
bedwyr
@Kys, it's best to edit your original question. I like to use "EDIT" statements to show where my answer has been revised.
bedwyr
I added the code to the question.
Brad Gilbert
+3  A: 

If you are running your test like so:

prove --lib t

Then your working directory is actually a level above t/

So in your package

package t::TestUtil;
use strict; use warnings;

And in your test_XXX.t

use lib '.';
use t::TestUtil;

I've seen it done this way in several CPAN modules.

snoopy
That's a good point: it would be helpful to know how the script is being invoked, and where the modules are located.
bedwyr
This worked! The fact that my working directory was a level above t/. Thanks snoopy, bedwyr and cberg!
Kys