Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Include Modules Automatically?

by kennethk (Abbot)
on Jan 05, 2009 at 19:41 UTC ( [id://734260]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://734260]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-26 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found