Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

ExtUtils::ModuleMaker vs h2xs

ExtUtils::ModuleMaker is a replacement for h2xs. So what's wrong with h2xs anyway and how does ExtUtils::ModuleMaker perform any better?

    h2xs -AXn Foo::Bar

    My annoyances with h2xs (these are purely personal):

    • by default: it produces code that isn't backwards compatible [see note] (our instead of use vars, use warnings, and use 5.00?)
    • you have extra work if you have more than one module in the distribution
    • you have lots of editing to do before you get started, (unless your name is A. U. Thor)
    • module code and tests are all dumped into the main directory

    On reflection, these seem quite petty -- but I am very lazy.

    perl -MExtUtils::ModuleMaker -e "Quick_Module ('Foo::Bar')"

    This is more to type, and produces similar results to h2xs. However there are the following improvements:

    • module files are neatly stored in a "lib" folder
    • test file is created in "t" subfolder
    • LICENSE file is included - defaults to perl license (GPL & Artistic)
    • lib/Foo/Bar.pm is backwards compatible with perl 5.005
    • useful pod sample for documenting subroutines

Advanced use of ExtUtils::ModuleMaker

The QuickModule() function still leaves A.U. Thor as the author of your work and other defaults and leaves you with only one module in your distribution. Use Generate_Module_Files() for a more complete solution...

    Generate_Module_Files()

    • Specify author details, (fills in the pod, Makefile.PL, etc)
    • Specify version number to start on
    • Specify the license that your module is released under (over 20 licenses included - or use custom)
    • Create module and test files for additional modules

Here is my code using ExtUtils::ModuleMaker that allows me to be extra lazy:

#!/usr/bin/perl5.6.1 -w use strict; use Getopt::Long; use ExtUtils::ModuleMaker; my %author = ( NAME => 'Simon Flack', EMAIL => 'simonflk@example.com', CPANID => 'SIMONFLK', WEBSITE => 'http://www.simonflack.com', ); # Set some defaults my $license = 'perl'; my $version = '0.1'; my $module_name = ''; my $extra_modules = ''; my @extra_modules = (); GetOptions ( 'name=s' => \$module_name, 'version:f' => \$version, 'license:s' => \$license, 'extra:s'=> \$extra_modules ); Usage() unless $module_name; ###################################################################### +######### # Now make the module ###################################################################### +######### push @extra_modules, {NAME => $_, ABSTRACT => $_} for split /,/, $extra_modules; Generate_Module_Files ( NAME => $module_name, ABSTRACT => $module_name, AUTHOR => \%author, VERSION => $version, LICENSE => $license, EXTRA_MODULES => \@extra_modules, ); sub Usage { my ($prog) = $0 =~ /\/([^\/]+)$/; print <<HELP; $prog - Simple Module Maker Usage: $prog <-name ModuleName> [-version=?] [-extra=?,?] [-license=?] Eg: $prog -name My::Module $prog -name My::Module -version 0.11 -extra My::Utils,My::Extra -license perl HELP }

Now I can write: "newmodule -n Foo::Bar -v 1.0 -l gpl" and I can start coding and writing tests straight away...

Note: If you use this, don't forget to change the author info.

Problems with ExtUtils::ModuleMaker

There aren't many.

  • ExtUtils::ModuleMaker won't be helpful if you are writing XS modules. You should stick to h2xs for this, probably.
  • The .pm files it creates encourage inline pod for documenting subroutines. I know a lot of people do this, but I prefer putting my pod at the bottom.
  • The test files are obscurely named, you'll probably want to rename them.

Reference:

See the following docs for more information about writing modules

update: h2xs compatibility
crazyinsomniac pointed out that h2xs has a backwards compatibility option "-b" I couldn't find this documented and it didn't work when I tried it (my v5.6.0 h2xs is higher up in the PATH than my 5.6.1 h2xs). It seems that is is a new option since perl5.6.1. I'll leave my original statement in here because it will still apply to some people on older perls. Thanks to crazyinsomniac for pointing out this option.


In reply to ExtUtils::ModuleMaker by simonflk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (13)
    As of 2014-10-30 14:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (208 votes), past polls