--- /dev/null
+package Module::Load;\r
+\r
+$VERSION = '0.10';\r
+\r
+use strict;\r
+use File::Spec ();\r
+\r
+sub import {\r
+ my $who = _who();\r
+\r
+ { no strict 'refs';\r
+ *{"${who}::load"} = *load;\r
+ }\r
+}\r
+\r
+sub load (*;@) {\r
+ my $mod = shift or return;\r
+ my $who = _who();\r
+\r
+ if( _is_file( $mod ) ) {\r
+ require $mod;\r
+ } else {\r
+ LOAD: {\r
+ my $err;\r
+ for my $flag ( qw[1 0] ) {\r
+ my $file = _to_file( $mod, $flag);\r
+ eval { require $file };\r
+ $@ ? $err .= $@ : last LOAD;\r
+ }\r
+ die $err if $err;\r
+ }\r
+ }\r
+ __PACKAGE__->_export_to_level(1, $mod, @_) if @_;\r
+}\r
+\r
+### 5.004's Exporter doesn't have export_to_level.\r
+### Taken from Michael Schwerns Test::More and slightly modified\r
+sub _export_to_level {\r
+ my $pkg = shift;\r
+ my $level = shift;\r
+ my $mod = shift;\r
+ my $callpkg = caller($level);\r
+\r
+ $mod->export($callpkg, @_);\r
+}\r
+\r
+sub _to_file{\r
+ local $_ = shift;\r
+ my $pm = shift || '';\r
+\r
+ my @parts = split /::/;\r
+\r
+ ### because of [perl #19213], see caveats ###\r
+ my $file = $^O eq 'MSWin32'\r
+ ? join "/", @parts\r
+ : File::Spec->catfile( @parts );\r
+\r
+ $file .= '.pm' if $pm;\r
+\r
+ return $file;\r
+}\r
+\r
+sub _who { (caller(1))[0] }\r
+\r
+sub _is_file {\r
+ local $_ = shift;\r
+ return /^\./ ? 1 :\r
+ /[^\w:']/ ? 1 :\r
+ undef\r
+ #' silly bbedit..\r
+}\r
+\r
+\r
+1;\r
+\r
+__END__\r
+\r
+=pod\r
+\r
+=head1 NAME\r
+\r
+Module::Load - runtime require of both modules and files\r
+\r
+=head1 SYNOPSIS\r
+\r
+ use Module::Load;\r
+\r
+ my $module = 'Data:Dumper';\r
+ load Data::Dumper; # loads that module\r
+ load 'Data::Dumper'; # ditto\r
+ load $module # tritto\r
+ \r
+ my $script = 'some/script.pl'\r
+ load $script;\r
+ load 'some/script.pl'; # use quotes because of punctuations\r
+ \r
+ load thing; # try 'thing' first, then 'thing.pm'\r
+\r
+ load CGI, ':standard' # like 'use CGI qw[:standard]'\r
+ \r
+\r
+=head1 DESCRIPTION\r
+\r
+C<load> eliminates the need to know whether you are trying to require\r
+either a file or a module.\r
+\r
+If you consult C<perldoc -f require> you will see that C<require> will\r
+behave differently when given a bareword or a string.\r
+\r
+In the case of a string, C<require> assumes you are wanting to load a\r
+file. But in the case of a bareword, it assumes you mean a module.\r
+\r
+This gives nasty overhead when you are trying to dynamically require\r
+modules at runtime, since you will need to change the module notation\r
+(C<Acme::Comment>) to a file notation fitting the particular platform\r
+you are on.\r
+\r
+C<load> elimates the need for this overhead and will just DWYM.\r
+\r
+=head1 Rules\r
+\r
+C<load> has the following rules to decide what it thinks you want:\r
+\r
+=over 4\r
+\r
+=item *\r
+\r
+If the argument has any characters in it other than those matching\r
+C<\w>, C<:> or C<'>, it must be a file\r
+\r
+=item *\r
+\r
+If the argument matches only C<[\w:']>, it must be a module\r
+\r
+=item *\r
+\r
+If the argument matches only C<\w>, it could either be a module or a\r
+file. We will try to find C<file> first in C<@INC> and if that fails,\r
+we will try to find C<file.pm> in @INC.\r
+If both fail, we die with the respective error messages.\r
+\r
+=back\r
+\r
+=head1 Caveats\r
+\r
+Because of a bug in perl (#19213), at least in version 5.6.1, we have\r
+to hardcode the path seperator for a require on Win32 to be C</>, like\r
+on Unix rather than the Win32 C<\>. Otherwise perl will not read it's\r
+own %INC accurately double load files if they are required again, or\r
+in the worst case, core dump.\r
+\r
+C<Module::Load> can not do implicit imports, only explicit imports.\r
+(in other words, you always have to specify expliclity what you wish\r
+to import from a module, even if the functions are in that modules'\r
+C<@EXPORT>)\r
+\r
+=head1 AUTHOR\r
+\r
+This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.\r
+\r
+Thanks to Jonas B. Nielsen for making explicit imports work.\r
+\r
+=head1 COPYRIGHT\r
+\r
+This module is\r
+copyright (c) 2002 Jos Boumans E<lt>kane@cpan.orgE<gt>.\r
+All rights reserved.\r
+\r
+This library is free software;\r
+you may redistribute and/or modify it under the same\r
+terms as Perl itself.\r
+\r
+=cut \r