Changeset 5987370 for perl/lib/BarnOwl


Ignore:
Timestamp:
Aug 20, 2008, 2:16:36 AM (13 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
167044b
Parents:
e9bb404
Message:
ModuleLoader.pm: Add a :reload command which reloads a single module
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl/ModuleLoader.pm

    r965e14d r5987370  
    88use PAR (BarnOwl::get_config_dir() . "/modules/*.par");
    99
     10our %modules;
     11
    1012sub load_all {
     13    my $class = shift;
     14    $class->rescan_modules;
     15
     16    for my $mod (keys %modules) {
     17        if(!defined eval "use BarnOwl::Module::$mod") {
     18            BarnOwl::error("Unable to load module $mod: \n$@\n") if $@;
     19        }
     20    }
     21
     22    $BarnOwl::Hooks::startup->add(\&register_keybindings);
     23}
     24
     25sub rescan_modules {
    1126    PAR::reload_libs();
    1227    PAR->import(BarnOwl::get_data_dir() . "/modules/*.par");
    1328    PAR->import(BarnOwl::get_config_dir() . "/modules/*.par");
    14     my %modules;
    1529    my @modules;
     30
     31    %modules = ();
    1632
    1733    my @moddirs = ();
     
    3753        }
    3854    }
    39     for my $class (keys %modules) {
    40         if(!defined eval "use BarnOwl::Module::$class") {
    41             # BarnOwl::error("Unable to load module $class: $!") if $!;
    42             BarnOwl::error("Unable to load module $class: \n$@\n") if $@;
    43         }
     55}
     56
     57sub reload_module {
     58    my $class = shift;
     59    my $module = shift;
     60
     61    $class->rescan_modules();
     62
     63    for my $m (keys %INC) {
     64        delete $INC{$m} if $m =~ m{^BarnOwl/Module/$module};
    4465    }
    4566
    46     $BarnOwl::Hooks::startup->add(\&register_keybindings);
     67    local $SIG{__WARN__} = \&squelch_redefine;
     68    if(!defined eval "use BarnOwl::Module::$module") {
     69        BarnOwl::error("Unable to load module $module: \n$@\n") if $@;
     70    }
     71}
     72
     73sub reload_cmd {
     74    my $class = shift;
     75    shift; # Command
     76    my $module = shift;
     77    unless(defined($module)) {
     78        die("Usage: reload [MODULE]");
     79    };
     80    $class->reload_module($module);
    4781}
    4882
     
    5286                           usage   => 'reload-modules',
    5387                           description => q{Reloads all modules located in ~/.owl/modules and the system modules directory}
     88                          });
     89    BarnOwl::new_command('reload', sub {BarnOwl::ModuleLoader->reload_cmd(@_)}, {
     90                           summary => 'Reload one module',
     91                           usage   => 'reload [MODULE]',
     92                           description => q{Reloads a single module located in ~/.owl/modules or the system modules directory}
    5493                          });
    5594}
Note: See TracChangeset for help on using the changeset viewer.