Thursday, August 4, 2011

Create a Perl Module Skeleton Using h2xs

The h2xs binary is used to convert C header files to Perl extensions, but it can also be used to create a Perl module template. Creating modules this way will save you a lot of time and make sure that your module is setup up correctly for submission to CPAN.

You can create your own module skeleton with h2xs using:

h2xs -A -X -n My::Module

This will create a directory called My-Module with the following files:

My-Module/MANIFEST is your actual module, which you will edit and add your desired functionality into. Your module can be installed on your system by following these steps:

perl Makefile.PL

This creates the makefile

make test

This executes all tests, assuming you have created some.

make install

This will install the module in your system, you may have to execute this line as super user.

You can package up your module for submission to CPAN, or other distribution means by typing:

make tardist

This will create My-Module-0.01.tar.gz inside your project directory.


  1. I tried this but how do you do a library if Me is your class and you want to add Me::One, Me::Two, etc. I tried putting them under lib/Me/ and it makes PODS for it but won't include it in the "make dist" tarball. I tried adding it to other places in the Makefile which has but it doesn't see that either. I also tried to put my files in there then do another "perl Makefile.PL" and the dist didn't put it in the new tarball either. I don't have permission to do a make install here so I don't know if it will work but since those sub-modules are not in the tarball then I'm doubting it.


  2. You need to add them to the MANIFEST file.

  3. Wow, What an Outstanding post. I found this too much informatics. It is what I was seeking for. I would like to recommend you that please keep sharing such type of info.If possible, Thanks. skeleton halloween costume diy

  4. It is a nice blog that you have posted here, and it contains a lot of useful information. Keep posting like this. I always enjoy reading your posts.

    Read my blog as well:
    Application development Company in Zirakpur

    Name: GS Web Technologies: Website, Mobile App Development, Graphic Designing and Digital Marketing Company in Zirakpur, India.

    Address: 3rd Floor, Paras Down Town Square Mall, Zirakpur, Punjab – 140603, India.

    Phone Number: +91- 9501406707