[282] in BarnOwl Developers
[D-O-H] r442 - / trunk/conf.asedeno/owl trunk/owl
daemon@ATHENA.MIT.EDU (hartmans@MIT.EDU)
Thu Oct 29 18:04:28 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: hartmans@MIT.EDU
Reply-To: dirty-owl-hackers@MIT.EDU
Date: Wed, 1 Nov 2006 01:00:22 -0500 (EST)
Author: hartmans
Date: 2006-11-01 01:00:20 -0500 (Wed, 01 Nov 2006)
New Revision: 442
Modified:
/
trunk/conf.asedeno/owl/owlconf.pl
trunk/owl/perlwrap.pm
Log:
r1346@luminous: hartmans | 2006-11-01 00:58:53 -0500
Move the module support system into perlwrap.pm
Add support for datadir modules.
Property changes on:
___________________________________________________________________
Name: svk:merge
- 6aa88b72-b502-0410-8cb4-a5dd0230fb79:/owl-local:1345
+ 6aa88b72-b502-0410-8cb4-a5dd0230fb79:/owl-local:1346
Modified: trunk/conf.asedeno/owl/owlconf.pl
===================================================================
--- trunk/conf.asedeno/owl/owlconf.pl 2006-11-01 06:00:11 UTC (rev 441)
+++ trunk/conf.asedeno/owl/owlconf.pl 2006-11-01 06:00:20 UTC (rev 442)
@@ -46,71 +46,14 @@
### change it and the revisions can be substantial. Instead, copy it to
### ~/.owl/owlconf.pl and set your ~/.owlconf to source it, or just put it at
### ~/.owlconf.
-###
-################################################################################
+our @onModuleHelp;
-# Arrays of function pointers to be called at specific times.
-our @onStartSubs = ();
-our @onReceiveMsg = undef;
-our @onModuleHelp = undef;
-our @onMainLoop = undef;
-our @onGetBuddyList = undef;
-
-################################################################################
-# Mainloop hook and threading.
-################################################################################
-
-use threads;
-use threads::shared;
-
-# Shared thread shutdown flag.
-# Consider adding a reload flag, so threads that should persist across reloads
-# can distinguish the two events. We wouldn't want a reload to cause us to
-# log out of and in to a perl-based IM session.
-our $shutdown : shared;
-$shutdown = 0;
-our $reload : shared;
-$reload = 0;
-
-sub owl::mainloop_hook
-{
- foreach (@onMainLoop)
- {
- &$_();
- }
- return;
-}
-
-################################################################################
-# Startup and Shutdown code
-################################################################################
-sub owl::startup
-{
-# Modern versions of owl provides a great place to have startup stuff.
-# Put things in ~/.owl/startup
-
+###
+push @owl::onStartSubs, sub {
# At this point I use owl::startup to pull in some hooks for reloading and
-# to set up keybindings specific to this file.
+ @onModuleHelp = ();# to set up keybindings specific to this file.
- onStart();
-}
-sub owl::shutdown
-{
-# Modern versions of owl provides a great place to have shutdown stuff.
-# Put things in ~/.owl/shutdown
-
-# At this point I use owl::shutdown to tell any auxillary threads that they
-# should terminate.
- $shutdown = 1;
- owl::mainloop_hook();
-}
-
-#Run this on start and reload. Adds modules and runs their startup functions.
-sub onStart
-{
- reload_init();
-
owl::command('alias modhelp perl moduleHelp()');
owl::command('bindkey recv "F2" command modhelp');
owl::command('bindkey recv "C-s C-d" command view -s default');
@@ -119,103 +62,9 @@
owl::command('bindkey recv END command last');
owl::command('bindkey edit DC command edit:delete-next-char');
- #So that the user's .owlconf can have startsubs, we don't clear
- #onStartSubs; reload does however
- @onReceiveMsg = ();
- @onModuleHelp = ();
- @onMainLoop = ();
- @onGetBuddyList = ();
-
- loadModules();
- foreach (@onStartSubs)
- {
- &$_();
- }
-
}
-################################################################################
-# Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl
-################################################################################
-sub reload_hook (@)
-{
- # Redefine this function in your .owlconf and include in it any
- # code you want to happen on a reload. I suggest you create
- # load_filters() and run it from here and owl::startup()
- # because owl::command() must be in a sub
-
- @onStartSubs = ();
- onStart();
- return 1;
-}
-sub reload
-{
- # Shutdown existing threads.
- $reload = 1;
- owl::mainloop_hook();
- $reload = 0;
- @onMainLoop = ();
-
- # Do reload
- if (do "$ENV{HOME}/.owlconf" && reload_hook(@_))
- {
- return "owlconf reloaded";
- }
- else
- {
- return "$ENV{HOME}/.owlconf load attempted, but error encountered:\n$@";
- }
-}
-
-sub reload_init ()
-{
- owl::command('alias reload perl reload');
- owl::command('bindkey global "C-x C-r" command reload');
-}
-
################################################################################
-# Loads modules from ~/.owl/modules
-################################################################################
-
-sub loadModules ()
-{
- opendir(MODULES, "$ENV{HOME}/.owl/modules");
- # source ./modules/*.pl
- my @modules = grep(/\.pl$/, readdir(MODULES));
- foreach my $mod (@modules)
- {
- do "$ENV{HOME}/.owl/modules/$mod";
- }
- closedir(MODULES);
-}
-
-################################################################################
-# Hooks into receive_msg()
-################################################################################
-
-sub owl::receive_msg
-{
- my $m = shift;
- foreach (@onReceiveMsg)
- {
- &$_($m);
- }
-}
-
-################################################################################
-# Hooks into get_blist()
-################################################################################
-
-sub owl::get_blist
-{
- my $m = shift;
- foreach (@onGetBuddyList)
- {
- &$_($m);
- }
-}
-
-################################################################################
# Module help system.
################################################################################
Modified: trunk/owl/perlwrap.pm
===================================================================
--- trunk/owl/perlwrap.pm 2006-11-01 06:00:11 UTC (rev 441)
+++ trunk/owl/perlwrap.pm 2006-11-01 06:00:20 UTC (rev 442)
@@ -280,9 +280,176 @@
#####################################################################
#####################################################################
+################################################################################
+package owl;
+# Arrays of function pointers to be called at specific times.
+our @onStartSubs = ();
+our @onReceiveMsg = undef;
+our @onMainLoop = undef;
+our @onGetBuddyList = undef;
+
+################################################################################
+# Mainloop hook and threading.
+################################################################################
+
+use threads;
+use threads::shared;
+
+# Shared thread shutdown flag.
+# Consider adding a reload flag, so threads that should persist across reloads
+# can distinguish the two events. We wouldn't want a reload to cause us to
+# log out of and in to a perl-based IM session.
+our $shutdown : shared;
+$shutdown = 0;
+our $reload : shared;
+$reload = 0;
+
+sub owl::mainloop_hook
+{
+ foreach (@onMainLoop)
+ {
+ &$_();
+ }
+ return;
+}
+
+################################################################################
+# Startup and Shutdown code
+################################################################################
+sub owl::startup
+{
+# Modern versions of owl provides a great place to have startup stuff.
+# Put things in ~/.owl/startup
+ onStart();
+}
+
+sub owl::shutdown
+{
+# Modern versions of owl provides a great place to have shutdown stuff.
+# Put things in ~/.owl/shutdown
+
+# At this point I use owl::shutdown to tell any auxillary threads that they
+# should terminate.
+ $shutdown = 1;
+ owl::mainloop_hook();
+}
+
+#Run this on start and reload. Adds modules and runs their startup functions.
+sub onStart
+{
+ reload_init();
+ #So that the user's .owlconf can have startsubs, we don't clear
+ #onStartSubs; reload does however
+ @onReceiveMsg = ();
+ @onMainLoop = ();
+ @onGetBuddyList = ();
+
+ loadModules();
+ foreach (@onStartSubs)
+ {
+ &$_();
+ }
+}
+################################################################################
+# Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl
+################################################################################
+sub reload_hook (@)
+{
+
+ @onStartSubs = ();
+ onStart();
+ return 1;
+}
+
+sub reload
+{
+ # Shutdown existing threads.
+ $reload = 1;
+ owl::mainloop_hook();
+ $reload = 0;
+ @onMainLoop = ();
+
+ # Do reload
+ if (do "$ENV{HOME}/.owlconf" && reload_hook(@_))
+ {
+ return "owlconf reloaded";
+ }
+ else
+ {
+ return "$ENV{HOME}/.owlconf load attempted, but error encountered:\n$@";
+ }
+}
+
+sub reload_init ()
+{
+ owl::command('alias reload perl reload');
+ owl::command('bindkey global "C-x C-r" command reload');
+}
+
+################################################################################
+# Loads modules from ~/.owl/modules and owl's data directory
+################################################################################
+
+sub loadModules ()
+{
+my @modules;
+foreach my $dir (owl::get_data_dir()."/owl/modules", $ENV{HOME}."/.owl/modules") {
+ opendir(MODULES, $dir);
+ # source ./modules/*.pl
+ @modules = grep(/\.pl$/, readdir(MODULES));
+
+foreach my $mod (@modules) {
+ do "$dir/$mod";
+}
+closedir(MODULES);
+}
+}
+sub queue_admin_msg
+{
+ my $err = shift;
+ my $m = owl::Message->new(type => 'admin',
+ direction => 'none',
+ body => $err);
+ owl::queue_message($m);
+}
+
+
+################################################################################
+# Hooks into receive_msg()
+################################################################################
+
+sub owl::receive_msg
+{
+ my $m = shift;
+ foreach (@onReceiveMsg)
+ {
+ &$_($m);
+ }
+}
+
+################################################################################
+# Hooks into get_blist()
+################################################################################
+
+sub owl::get_blist
+{
+ my $m = shift;
+ foreach (@onGetBuddyList)
+ {
+ &$_($m);
+ }
+}
+
# switch to package main when we're done
package main;
+# alias the hooks
+foreach my $hook qw (onStartSubs
+onReceiveMsg
+onMainLoop
+onGetBuddyList ) {
+ *{"main::".$hook} = \*{"owl::".$hook};
+}
# load the config file
if (-r $owl::configfile) {