- Timestamp:
- Sep 11, 2010, 5:25:04 PM (14 years ago)
- Branches:
- master, release-1.10, release-1.7, release-1.8, release-1.9
- Children:
- 0743696
- Parents:
- 8106870
- git-author:
- Nelson Elhage <nelhage@mit.edu> (09/11/10 16:46:51)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (09/11/10 17:25:04)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/lib/BarnOwl/ModuleLoader.pm
r41bbb8a rf544216 4 4 package BarnOwl::ModuleLoader; 5 5 6 use lib (BarnOwl::get_data_dir() . "/modules/"); 7 use PAR (BarnOwl::get_data_dir() . "/modules/*.par"); 8 use PAR (BarnOwl::get_config_dir() . "/modules/*.par"); 6 use PAR; 9 7 10 8 our %modules; … … 24 22 } 25 23 24 =h2 rescan_modules 25 26 Re-compute the list of available modules, and add the necessary items to @INC 27 and @PAR_INC. 28 29 We load modules from two directories, the system module dir, and the user module 30 directory. Modules can be in either of two forms: ${modname}.par, or else a 31 ${modname}/ directory containing lib/${modname}. 32 33 We prefer to load modules from the user's directory, and if a module exists in 34 both packed and unpacked form in the same directory, we prefer the unpacked 35 module. 36 37 We walk the module directories in order of ascending priority -- user directory, 38 and then system directory. 39 40 When we walk the directories, we first check all things that are not named 41 Foo.par, add them to @INC, and add them to the module list. We then walk the 42 .par files and add them to @PAR_INC and update the module list. 43 44 It is important that we never add a module to @INC (or @PAR_INC) if we already 45 have a source for it, in order to get priorities right. The reason is that @INC 46 is processed before @PAR_INC, so if we had an unpacked system module and a 47 packed local module, if we added both, the system module would take priority. 48 49 =cut 50 26 51 sub rescan_modules { 27 PAR->import(BarnOwl::get_data_dir() . "/modules/*.par"); 28 PAR->import(BarnOwl::get_config_dir() . "/modules/*.par"); 29 my @modules; 52 @PAR::PAR_INC = (); 30 53 31 54 %modules = (); 32 55 33 56 my @moddirs = (); 57 push @moddirs, BarnOwl::get_config_dir() . "/modules"; 34 58 push @moddirs, BarnOwl::get_data_dir() . "/modules"; 35 push @moddirs, BarnOwl::get_config_dir() . "/modules"; 36 59 37 60 for my $dir (@moddirs) { 61 # Strip defunct entries from @INC 62 @INC = grep {!/^\Q$dir/} @INC; 63 38 64 opendir(my $dh, $dir) or next; 39 while(defined(my $f = readdir($dh))) { 40 next if $f =~ /^\./; 41 if(-f "$dir/$f" && $f =~ /^(.+)\.par$/) { 42 $modules{$1} = 1; 43 } elsif(-d "$dir/$f" && -d "$dir/$f/lib") { 65 my @ents = grep {!/^\./} readdir($dh); 66 67 # Walk unpacked modules 68 for my $f (grep {!/\.par$/} @ents) { 69 if(-d "$dir/$f" && -d "$dir/$f/lib") { 70 next if $modules{$f}; 71 44 72 unshift @INC, "$dir/$f/lib" unless grep m{^$dir/$f/lib$}, @INC; 45 73 $modules{$f} = 1; 46 74 } 47 75 } 48 @modules = grep /\.par$/, readdir($dh); 76 77 # Walk parfiles 78 for my $f (grep /\.par$/, @ents) { 79 if(-f "$dir/$f" && $f =~ /^(.+)\.par$/) { 80 next if $modules{$1}; 81 82 PAR->import("$dir/$f"); 83 $modules{$1} = 1; 84 } 85 } 86 49 87 closedir($dh); 50 for my $mod (@modules) {51 my ($class) = ($mod =~ /^(.+)\.par$/);52 $modules{$class} = 1;53 }54 88 } 55 89 }
Note: See TracChangeset
for help on using the changeset viewer.