Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Tutorial on making a proper module?

by Cody Fendant (Friar)
on Jan 14, 2016 at 00:05 UTC ( #1152728=perlquestion: print w/replies, xml ) Need Help??
Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

I've created a module for my own purposes to access a particular SOAP interface.

All I've really done is make some .pm files which do what I want.

What are the steps I should follow if I want to make it a proper installable module with tests, which cpan etc. would place in the system path? Which tests should I write, at a minimum? Is there a good tutorial on this which Monks recommend?

Followup question: there are non-perl files (XML Templates) used by the module. What's the right way to place those files in order for the module to find them? Can I just put them in a templates directory inside the module's directory?

Replies are listed 'Best First'.
Re: Tutorial on making a proper module?
by stevieb (Abbot) on Jan 14, 2016 at 00:23 UTC

    choroba has (or been party to helping) put this together. Check it out and see if it works for you.

    As far as the templates, yes, put them in a templates directory. If you need them installed as part of your *distribution* (that's what we call a CPAN package), personally, I'd use the Makefile (or Build file) to drop them into the appropriate location.

    Head on over to MetaCPAN and take a look at the structure of some of the distributions. You'll see structure, test layout etc. Reviewing ones that the Testers link states is passing most (if not all) the tests is a good way to understand a properly structured and designed dist. I'd recommend to look at one of mine, but that'd be biased. Data::Compare is one that may help, that has a decent structure for a newb to CPAN to look at. It does not have extra directories (such as templates), but I think it'll help you get you on your way.

    I'll let the other CPAN Monks speak up now.

      That tutorial is very good, thanks a lot for that. I will definitely follow it.

      I have one specific question about the templates thing still unanswered though. Say I have a module like this, and there's an essential file right there in the same directory as

      package TestModule; open( FILE, '<', 'essential_file.txt' ) or die("Can't open file"); 1;

      and I run it like this:

      require TestModule; print "hello world";

      It will fail (unless the script is in the same directory as TestModule).

      I'm probably missing something obvious but how do I get the file path right so that can find its file, no matter where it's called from?

Re: Tutorial on making a proper module?
by toolic (Bishop) on Jan 14, 2016 at 00:54 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1152728]
Approved by Paladin
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2018-07-21 17:54 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (449 votes). Check out past polls.