Acme-AutoloadAll
view release on metacpan or search on metacpan
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
lib/Acme/AutoloadAll.pm view on Meta::CPAN
sub find_function {
my $function = shift;
my $package = shift || 'main';
my $seen = shift || {};
# remove last ::
$package =~ s/::$//;
return undef if (exists($seen->{$package}));
print STDERR "Searching '$function' in '$package'...\n" if ($DEBUG);
# check if the current package has the function
my $sub = $package->can($function);
print STDERR "Found!\n" if ($DEBUG && (ref($sub) eq 'CODE'));
return $sub if (ref($sub) eq 'CODE');
$seen->{$package} = 1;
# check sub packages
my $symbols = do { no strict 'refs'; \%{$package . '::'} };
my @packages = grep { $_ =~ m/::$/ } keys(%$symbols);
foreach my $pkg (@packages) {
$pkg = $package . '::' . $pkg unless ($package eq 'main');
$sub = find_function($function, $pkg, $seen);
return $sub if (ref($sub) eq 'CODE');
}
# not found
return undef;
}
sub UNIVERSAL::AUTOLOAD {
(my $function = $UNIVERSAL::AUTOLOAD) =~ s/.*:://;
my $sub = find_function($function);
print STDERR "Not found!\n" if ($DEBUG && (ref($sub) ne 'CODE'));
goto &$sub if (ref($sub) eq 'CODE');
}
1;
__END__
=pod
=encoding UTF-8
lib/Acme/AutoloadAll.pm view on Meta::CPAN
=head1 VERSION
version 0.005
=head1 SYNOPSIS
use Scalar::Util ();
use Acme::AutoloadAll;
if (looks_like_number(42)) {
print "yay\n";
}
=head1 DESCRIPTION
This module allows you to call any function ever seen by your perl instance.
As long as you used/required a module in the past you can now call its functions everywhere.
=head1 HOW IT WORKS
The module puts an AUTOLOAD sub into UNIVERSAL so every package has it.
( run in 0.889 second using v1.01-cache-2.11-cpan-de7293f3b23 )