[Melbourne-pm] Perl best practices: script actions based on a command line argument

Brad Bowman list at bereft.net
Thu Jan 31 22:19:31 PST 2008


> So, what is the general consensus on the best way to do this -- what is
> the nicest way to dispatch to the various command handlers based on a
> command line argument?

I found the way svk dispatched to it's various sub-commands interesting,
although the details have faded from my mind.

Scanning through again, I think svk calls
   SVK::Command->invoke(..., $cmd, ... @ARGV);

  (SVK::Command->invoke loads the corresponding class SVK::Command::$name)

SVK::Command is a base class and namespace for other commands, providing
some option handling and utility methods.  Commands are in their own
modules like SVK::Command::Add.  They provide a "run" method,
options list and various other things.  This might be a bit
overblown for your situation.

   http://search.cpan.org/~clkao/SVK-v2.0.2/lib/SVK/Command.pm

Brad

PS. "XD" is Working Copy.  This may help make the code clearer.

-- 
In the judgement of the elders, a samurai's obstinacy should be excessive.
A thing done with moderation may later be judged insufficient.  I have heard
that when one thinks he has gone too far, he will not have erred.  This sort
of rule should not be forgotten.     -- Hagakure http://bereft.net/hagakure/


More information about the Melbourne-pm mailing list