in reply to Include Modules Automatically?
The following module will import every module in directory Foo and export everything the submodules export, and is a potential security risk for pathological file names:
package Foo; use strict; BEGIN { my @modules = (); opendir DIRHANDLE, 'Foo'; while (my $file = readdir DIRHANDLE) { if ($file =~ /\.pm$/) { $file=~s/\.pm//; push @modules, $file; } } closedir DIRHANDLE; require Exporter; our @ISA = qw(Exporter); our @EXPORT = (); for my $module (@modules) { eval 'use Foo::'.$module; { no strict 'refs'; push @EXPORT, @{"Foo\:\:$module\:\:EXPORT"}; } }; } 1;
Update: Forgot to close the directory handle.
|
|---|