• Use Getopt::Long even if you don't think you need to

    Thread over on perlmonks talks about Tom Christiansen's assertion that you should use it, by default, even when you only have one command-line argument to parse:

    What seems to happen is that at first we just want to add--oh say for example JUST ONE, SINGLE LITTLE -v flag. Well, that's so easy enough to hand-hack, that of course we do so... But just like any other piece of software, these things all seem to have a way of overgrowing their original expectations... Getopt::Long is just *wonderful*, up--I believe--to any job you can come up with for it. Too often its absence means that I've in the long run made more work for myself--or others--by not having used it originally. [Emphasis mine -- Andy]

    I can't agree more. I don't care if you use Getopt::Long or Getopt::Declare or Getopt::Lucid or any of the other variants out there. You know know know that you're going to add more arguments down the road, so why not start out right?

    Yes, it can be tricky to get through all of its magic if you're unfamiliar with it, but it's pretty obvious when you see enough examples. Take a look at prove or ack for examples. mech-dump is pretty decent as an example as well:

    GetOptions(
    'user=s'        => $user,
    'password=s'    => $pass,
    forms           => sub { push( @actions, &dump_forms ); },
    links           => sub { push( @actions, &dump_links ); },
    images          => sub { push( @actions, &dump_images ); },
    all             => sub { push( @actions, &dump_forms, &dump_links, &dump_images ); },
    absolute        => $absolute,
    'agent=s'       => $agent,
    'agent-alias=s' => $agent_alias,
    help            => sub { pod2usage(1); },
    ) or pod2usage(2);
    

    Where the value in the hashref is a variable reference, the value gets stored in there. Where it's a sub, that sub gets executed with the arguments passed in. That's the basics, and you don't have to worry about anything else. Your user can pass --abs instead of --absolute if it's unambiguous. You can have mandatory flags, as in agent=s, where --agent must take a string. On and on, it's probably got the functionality you need.

    One crucial reminder: You must check the return code of GetOptions. Otherwise, your program will carry on. If someone gives your program an invalid argument on the command-line, then you know that the program cannot possibly be running in the way the user intended. Your program must stop immediately.

    Not checking the return of GetOptions is as bad as not checking the return of open. In fact, I think I smell a new Perl Critic policy....

  • My schedule for YAPC::NA 2008

    At work, we're planning the talks we want to go see at YAPC::NA in June. Here's the stuff that I wanna go see:

    • Monday
    • Tuesday
      • 08:15: Social Perl (Facebook apps): Writing Facebook apps is going to be my new stretch project I think. I don't know what I want to do, but FB as app platform is clearly going some place.
      • 08:40: Fey::ORM: Mmmm, object mapping. I hate ORMs, and Dave Rolsky and I have talked about why they suck, so maybe his new one sucks less.
      • 09:05: Perl 5 VM: Every conference needs a session that hurts your head!
      • 10:05: Moose: All the cool kids are all about the Moose!
      • 10:55: Rakudo: As someone who contributes to Parrot and Rakudo, I really don't know much about its guts.
      • 13:00: Catalyst workshop: Catalyst seems ready to be the Perl Rails.
      • 14:50: pQuery and jQuery: I don't know jQuery at all, and JavaScript frameworks are beyond me. Let's hope this is a good introduction.
      • 16:05: Smolderbot: We use the smolderbot, but we don't yet have it running PHP tests. :-(
    • Wednesday

    I'm also planning on being at the Parrot hackathon and the Sox game.

    RJBS and hdp have posted their itineraries and commentary as well. If you post yours somewhere, please leave a comment here.

  • Oslo QA hackathon wrapup

    In April, a dozen or so folks interested in Perl and testing got together in Oslo, Norway for a hackathon. This video gives a recap of what they accomplished.

    [vimeo http://www.vimeo.com/1043143 w=400&h=225] Oslo QA Hackathon, Closing Remarks from Stonehenge on Vimeo.

    Nice way to recap the proceedings!

  • Help the Perl 5 wiki get to 1,000 entries

    Aaron Trevena wants to get the Perl 5 wiki up to 1,000 pages, and it's almost at 900.

    The Most Wanted Pages is a great place to start. Pick a page that some other page has linked to, and create it. It's that simple.

  • Pragmatic Programmer on estimating

    From The Pragmatic Programmer:

    What's the value of pi? If you're wondering how much edging to put around a circular flower bed, then "3" is probably good enough. If you're in school, then maybe "22/7" is a good approximation. If you're in NASA, then maybe 12 decimal places will do.