Tuesday, June 24, 2014

Publishing your first Perl Module on CPAN



If you're thinking of writing a Perl module for CPAN, then you've probably got some experience with Perl and probably have a good reason to write the module.

I'll use myself as the example here since I recently went through the pain of getting my module published on CPAN.  I wrote my module as a wrapper for the API released for the Neurio sensor (see my last post).

Make sure your module has some basic features like:
use warnings;use strict;

I created my module structure using h2xs
h2xs -AXc -n NameSpace::NewModule

One very important thing to include is the version since CPAN will use this when verifying your module.  You cannot (or should not) submit the same version of your module twice.  Always increase the version number.
our $VERSION = '0.03';

Also make sure your module has correct and meaning full POD (Plain Old Documentation).  You can check out mine on CPAN

Once you've added your code and got it working, you'll need to package it up.

In your module folder you'll find a lib folder.  Your module goes in there
There will also be a file called Makefile.PL.  Run this as follows:
perl Makefile.pl

It will generate a real make file.  So now run this to build your distribution package:
sudo make dist

It will produce a compressed tar file.

At this point you're ready to upload to CPAN

You'll need to create an account and register a namespace.

CPAN will automatically verify and test your module and it should be available within an hour or so.

Check out my YouTube channel:  www.youtube.com/KedarWarriner




No comments:

Post a Comment