http://www.perlmonks.org?node_id=316335

I apologize if this meditation is somewhat rambling, but free association is a valid meditation technique, right? ;^)

Nearly a year ago, when the feature was first discussed, I posted Perl 6's part(). For those who aren't aware, part() is a new built-in that will come with Perl 6; it's essentially used to categorize ("partition") a list, dividing it into several lists based on an index returned by a coderef.

Since then, I've drifted away somewhat from the Perl community, mostly into message-board RPGs. It's not that I haven't been hacking Perl in the last year, merely that my "community time" has been spent elsewhere. Well, this weekend the board I've been spending most of my time on went down for upgrades. With winter break and nothing to read either online or off, I revisited the Monastery and looked over some of my old nodes.

The node above came to my attention; I realized that, although I had perfected the essentially-four-line function eleven months ago, I'd never done anything with it. So I spent today packaging it up into List::Part.

The most important thing for getting this finished was one that I did at the very start: I used h2xs immediately to create the directory I would build the module in. Why is this so important? Because it builds all the little auxilary files for you. If I had just sat down and hacked, like I often do when I feel like making a module, I would have stopped when it was time to build all those little files, simply because I wasn't sure where to begin.

I don't know about other people, but this is a chronic problem for me: I stop working on a module when I'm finished and have to build all the other files around it. The same is true of the related case, where I make a module for one program and then realize it's generally applicable. I'm not quite sure what would fix this; perhaps a new h2xs mode that worked with an existing .pm, or a different tool. Maybe it's something I haven't thought of. Maybe it's even just that I need to discipline myself more. Thoughts on this?

=cut
--Brent Dax
There is no sig.

Replies are listed 'Best First'.
Re: Thoughts on making modules
by liz (Monsignor) on Dec 22, 2003 at 09:39 UTC
    I always copy one of the "most appropriate" other modules file structures of CPAN modules that I have and start making changes to that. At least that way it has all of the specifics that I need in my modules (e.g. copyright notice).

    I think it is all about discipline, whether you use h2xs or your own solution.

    One tip I've picked up from an article Johan Vromans wrote long ago: I have a "src" directory that contains all the sources of all modules that I work on. For each CPAN uploadable distribution I have a seperate directory structure. The .pm files in there are actually symlinks to the appropriate files in the "src" directory. This allows you to work from the distribution or from your "src" directory, whichever is more convenient to you at the time.

    Liz

Adding POD Skeletons Automatically
by chromatic (Archbishop) on Dec 22, 2003 at 17:15 UTC

    I usually copy over Build.PL and Makefile.PL (compatibility mode) from an existing module.

    Laying out documentation is my least favorite part of writing. I use a vim macro to insert a POD skeleton: map ,pod <ESC>:r ~/bin/data/base.pod<CR>. That includes this file:

    __END__ =head1 NAME =head1 SYNOPSIS =head1 DESCRIPTION =head1 METHODS =over 4 =back =head1 AUTHOR chromatic =head1 BUGS No known bugs. =head1 COPYRIGHT Copyright (c) 2003, chromatic. All rights reserved. This module is d +istributed under the same terms as Perl itself, in the hope that it is useful but certainly under no guarantee.

    It's a lot easier to write my documentation then.

Re: Thoughts on making modules
by Juerd (Abbot) on Dec 22, 2003 at 19:14 UTC

    perhaps a new h2xs mode that worked with an existing .pm, or a different tool.

    I always write the .pm first, test it and then use h2xs. After using h2xs, I copy the module over.

    Then, if I am going to submit it to CPAN, I make things a little shinier by removing silly comments from Makefile.PL and t/1.t.

    So why not just use h2xs and then replace the .pm it generated? There's no need for a new tool to do that, I think :)

    Now if only there was something that automated writing regression tests...

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      I have a tool for that, too. It's ~/bin/newtest:

      #!/usr/bin/perl -w use strict; use File::Path; use File::Basename; my $progfile = basename( $0 ); die "$progfile <modname> <test filename>\n" unless @ARGV >= 2; my ($modname, $filename) = @ARGV; my $filepath = dirname( $filename ); mkpath( $filepath ) unless -e $filepath; open my $out, '>', $filename or die "Can't open '$filename': $!"; print $out <<END_HERE; #!/usr/bin/perl -w BEGIN { chdir 't' if -d 't'; use lib '../lib', '../blib/lib'; } use strict; use Test::More 'no_plan'; # tests => 1; my \$module = '$modname'; use_ok( \$module ) or exit; END_HERE

      For Some::Module, run newtest Some::Module t/testfile.t.

        Hm, that's kind of what h2xs also generates. But I was talking about the actual unit tests, more than just use_ok. Wouldn't it be great if with one simple command, something would analyze a requirements list and translate it to tests? But if that were possible, we could also make it write the code itself, and we'd be out of a job.

        Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Re: Thoughts on making modules
by PodMaster (Abbot) on Dec 25, 2003 at 09:24 UTC
    Well, as of late, I've been using a modified (fixes a few bugs reported on rt, customized to my liking) version of modulemaker, the commandline frontend to ExtUtils::ModuleMaker. I thought i'd mention it since nobody else seems to have.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Thoughts on making modules
by Anonymous Monk on Dec 23, 2003 at 07:55 UTC
    I am not writing re-usable modules at the moment, but when I was, ZOCCAV's PerlBean on CPAN was what I used for OO modules. You contribute the code and the class relations. PerlBean generates the files and the POD. I thought there must be other CPAN modules that do the same thing, rather than have to use h2xs.
Re: Thoughts on making modules
by Abigail-II (Bishop) on Dec 25, 2003 at 01:58 UTC
    I typically use h2xs and then throw away all files but Makefile.PL, because I'm too lazy to remember its syntax. The files created I either don't need, or they are just full of content I don't need.

    Abigail