Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Tutorial on making a proper module?

by stevieb (Canon)
on Jan 14, 2016 at 00:23 UTC ( [id://1152729]=note: print w/replies, xml ) Need Help??


in reply to Tutorial on making a proper module?

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.

Replies are listed 'Best First'.
Re^2: Tutorial on making a proper module?
by Cody Fendant (Hermit) on Jan 14, 2016 at 03:50 UTC

    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 TestModule.pm

    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 TestModule.pm can find its file, no matter where it's called from?

        Is it still broken? This reply to the discussion you linked to hints otherwise.
        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        OK that's more complex than I was hoping for, but that's very helpful, thanks.

        I might just stuff them into scalars and add another module to return them for the time being. Don't judge me!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1152729]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-03-29 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found