Well I guess it was going to happen sooner or later, consider :

package Foo;
use strict;
use Text::Soundex;
use File::Basename;
use Devel::Symdump;

use Dircon::Billing::AutoID;

my $obj = Devel::Symdump->new(__PACKAGE__);

no strict 'refs';

my %funcs = map { s/.*://; (soundex($_),\&{$_} ) } $obj->functions();

my ($name, $path, $ext )  = fileparse($0,'\..+');

my $sname = soundex($name);

if ( exists $funcs{$sname} )
   print $funcs{$sname}->(@ARGV);
   die "$0: $name not defined\n";

Then of course calling the program something like one of subroutines
defined in or imported into the current package will cause that subroutine
to be run with @ARGV as its arguments.

I was tempted to use the above code in the real world, but I plumped for
something similar without the subroutine discovery and without the soundex
- the program name -> subroutime mapping hard-coded in.  I sometimes think
of the sanity of those that might follow.


Reply via email to