use strict; use Sub::Approx; sub aa { print "You called 'aa'\n"; } &a; #### package Sub::Approx; use strict; use vars qw($VERSION $AUTOLOAD); use Text::Soundex; $VERSION = '0.01'; sub import { no strict 'refs'; # WARNING: Deep magic here! my $pkg = caller(0); *{"${pkg}::AUTOLOAD"} = \&AUTOLOAD; } sub AUTOLOAD { my %cache; my @c = caller(0); my ($pkg, $sub) = $AUTOLOAD =~ /^(.*)::(.*)$/; no strict 'refs'; # WARNING: Deep magic here! foreach (keys %{"${pkg}::"}) { my $glob = $::{$_}; $glob =~ s/^\*${pkg}:://; push @{$cache{soundex($glob)}}, $glob if defined &{"*${pkg}::$glob"}; } $sub = soundex($sub); if (exists $cache{$sub}) { my @f = @{$cache{$sub}}; $sub = "${pkg}::$f[rand @f]"; goto &$sub; } else { die "REALLY Undefined subroutine $AUTOLOAD called at $c[1] line $c[2]\n"; } } 1;