Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

how do you build and test your modules locally before publishing

by gideondsouza (Pilgrim)
on Dec 31, 2012 at 02:03 UTC ( #1010971=perlquestion: print w/ replies, xml ) Need Help??
gideondsouza has asked for the wisdom of the Perl Monks concerning the following question:

I've been trying my hand at making a simple perl module.

Now, so far I write this on the top of the file where I want to use the module to test it out:

use lib("path_to_my_module/lib");

Everything works ok till I try to run the default tests (generated by module starter). I get:

#   Failed test 'use Dancer::Plugin::Foo;'
#   at t/00-load.t line 12.
#     Tried to use 'Dancer::Plugin::Foo'.
#     Error:  Can't locate Dancer/Plugin/
It fails this test:
BEGIN { use_ok( 'Dancer::Plugin::Foo' ) || print "Bail out!\n"; }
Thats all because the path is not right. But, even if I use use lib(path to_module) it doesn't work.

How do you guys usually use and test your modules locally before publishing them? How should I get the test to pass? I can't just add a use lib there!

Comment on how do you build and test your modules locally before publishing
Select or Download Code
Re: how do you build and test your modules locally before publishing
by davido (Archbishop) on Dec 31, 2012 at 02:27 UTC

    prove has the "-b" and "-I" switches, which can be used to specify where to find the library(s) that the tests need to use. For example, if MyMod::Foo hasn't been built yet, and just exists in a distribution tree such as:


    ...and my tests are in...


    Then I could 'cd' into MyMod-Foo, and execute the following:

    prove -Ilib

    This assumes the module doesn't require any special build process (for example, no XS, no Makefile.PL trickery). Or if my module has a Makefile.PM that conforms to the normal module building standards:

    perl Makefile.PL make prove -b

    ...which first builds the module into a "blib" (build lib) directory, and then tells 'prove' to look in the MyModule-Foo/blib/ directory for the temporary built version of the module.

    Perl also has the -I switch (that's -I as in Include -- <<corrected-thanks tobyink>> -- documented in perlrun. So once again, I could 'cd' into MyModule-Foo/ and type: perl -Ilib t/00-load.t, again assuming that the development version of the module resides in MyModule-Foo/lib/MyModule/

    If the module is standards conforming, you can use a version of the mantra: perl Makefile.PL, make, and make test, or perl Build.PL, Build, and Build test. Many authors also use environment variables to control what tests run. Additional information on distribution maintenance commands can be found in ExtUtils::MakeMaker


      Thanks very much for your reply davido. Exactly what I was looking for

      One more little query, the perldoc command doesn't seem to have a -I switch. How should I test if the POD I've written looks ok? How is it usually done?

        Test::Pod, and Test::Pod::Coverage, if memory serves. Also, Perl::Critic: One of the elevated levels of whining will grouse at you if your POD is missing sections common to modules. I think Test::Kwalitee does some POD diving too, but half the time I can't even get it to install all of its deps. Test::Kwalitee and Test::PerlCritic should always be "author-only" tests, by the way.


        perldoc allows you to provide a file path rather than a module name...

        perldoc File::Spec perldoc lib/Foo/

        I tend to view my pod in an 80x24 terminal to check there's no ugly line wrapping issues at that size.

        I also check with Test::Pod and Test::Pod::Coverage.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      Huh? On my system at least, the perl option for setting a library path is an upper-case "i":

      perl -Ilib t/00-load.t

      That is, the same as prove. The lower-case "L" option (perl -l) is line end processing for one-liners.

      prove -l (lower-case "L") is a useful shortcut for prove -Ilib.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

        Corrected. ...sometimes things that are "force of habit" become difficult to explain. And somehow in so-doing, I managed to confuse myself. :) Thanks for the nudge.


Re: how do you build and test your modules locally before publishing
by Anonymous Monk on Dec 31, 2012 at 02:29 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1010971]
Approved by davido
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-09-20 15:48 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (160 votes), past polls