Modules: Making your own

Read about CPAN modules

The definitive book,even though it's a few years old,is Sam Tregar's Writing Perl Modules For CPAN.It's available for free download at http://apress.com/book/free.

Create new modules with Module::Starter

Module::Starter and its command-line tool module-starter creates the basic framework for a module distribution suitable for putting on the CPAN.It includes basic code layout,POD directives and documentation skeleton,basic tests,the Makefile.PL and MANIFEST files,and the start of README and Changes logs.

  1. $ module-starter --module=Magic::Foo --module=Magic::Foo::Internals \
  2. --author="Andy Lester" --email="andy@perl.org" --verbose
  3. Created Magic-Foo
  4. Created Magic-Foo/lib/Magic
  5. Created Magic-Foo/lib/Magic/Foo.pm
  6. Created Magic-Foo/lib/Magic/Foo
  7. Created Magic-Foo/lib/Magic/Foo/Internals.pm
  8. Created Magic-Foo/t
  9. Created Magic-Foo/t/pod-coverage.t
  10. Created Magic-Foo/t/pod.t
  11. Created Magic-Foo/t/boilerplate.t
  12. Created Magic-Foo/t/00-load.t
  13. Created Magic-Foo/.cvsignore
  14. Created Magic-Foo/Makefile.PL
  15. Created Magic-Foo/Changes
  16. Created Magic-Foo/README
  17. Created Magic-Foo/MANIFEST
  18. Created starter directories and files

Create XS modules with h2xs

If you're creating an XS module, where you're interfacing Perl code with external C code, you'll need to use the original module-starting tool, h2xs. h2xs is included with every Perl distribution, and many was originally grown into a generic module starter, but it's not nearly as up-to-date in what it does as Module::Starter. Unless you need XS code, stick with Module::Starter.

Put your module on the CPAN


Want to contribute?

Submit a PR to github.com/petdance/perl101