Index: functions.c
===================================================================
--- functions.c	(revision 25729b21b3c139d2c02bdf0250c26f5b18d07051)
+++ functions.c	(revision 8203afdd0879526e14674b39e741493894354216)
@@ -1030,5 +1030,5 @@
 
   /* execute the commands in shutdown */
-  ret = owl_perlconfig_execute("owl::shutdown();");
+  ret = owl_perlconfig_execute("BarnOwl::Hooks::shutdown();");
   if (ret) owl_free(ret);
 
@@ -3316,6 +3316,6 @@
 
   if(aim && zephyr) {
-      if(owl_perlconfig_is_function("owl::get_blist")) {
-          char * perlblist = owl_perlconfig_execute("owl::get_blist()");
+      if(owl_perlconfig_is_function("BarnOwl::Hooks::get_blist")) {
+          char * perlblist = owl_perlconfig_execute("BarnOwl::Hooks::get_blist()");
           if(perlblist) {
               owl_fmtext_append_ztext(&fm, perlblist);
Index: owl.c
===================================================================
--- owl.c	(revision 00f9a7dd1307a0449452c14e2892fb699f3799e0)
+++ owl.c	(revision 8203afdd0879526e14674b39e741493894354216)
@@ -319,6 +319,6 @@
     owl_function_debugmsg("Found perl formatting");
     s=owl_malloc(sizeof(owl_style));
-    owl_style_create_perl(s, "perl", "owl::_format_msg_legacy_wrap",
-			  "User-defined perl style that calls owl::format_msg"
+    owl_style_create_perl(s, "perl", "BarnOwl::_format_msg_legacy_wrap",
+			  "User-defined perl style that calls BarnOwl::format_msg"
 			  "with legacy global variable support");
     owl_global_add_style(&g, s);
@@ -328,5 +328,5 @@
   /* execute the startup function in the configfile */
   owl_function_debugmsg("startup: executing perl startup, if applicable");
-  perlout = owl_perlconfig_execute("owl::startup();");
+  perlout = owl_perlconfig_execute("BarnOwl::Hooks::startup();");
   if (perlout) owl_free(perlout);
   
@@ -439,8 +439,5 @@
     }
 
-    /* Hook perl into the loop */
-    if (owl_perlconfig_is_function("owl::mainloop_hook")) {
-	 owl_perlconfig_mainloop();
-    }
+    owl_perlconfig_mainloop();
 
     /* little hack */
Index: perlconfig.c
===================================================================
--- perlconfig.c	(revision 9364a36ade2604a24e778a1264848f893d231998)
+++ perlconfig.c	(revision 8203afdd0879526e14674b39e741493894354216)
@@ -12,5 +12,5 @@
 extern char *owl_perlwrap_codebuff;
 
-extern XS(boot_owl);
+extern XS(boot_BarnOwl);
 extern XS(boot_DynaLoader);
 // extern XS(boot_DBI);
@@ -21,5 +21,5 @@
   dXSUB_SYS;
   {
-    newXS("owl::bootstrap", boot_owl, file);
+    newXS("BarnOwl::bootstrap", boot_BarnOwl, file);
     newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
   }
@@ -86,10 +86,10 @@
   hv_store(h, "private", strlen("private"), newSViv(owl_message_is_private(m)),0);
 
-  if (owl_message_is_type_zephyr(m))       blessas = "owl::Message::Zephyr";
-  else if (owl_message_is_type_aim(m))     blessas = "owl::Message::AIM";
-  else if (owl_message_is_type_jabber(m))  blessas = "owl::Message::Jabber";
-  else if (owl_message_is_type_admin(m))   blessas = "owl::Message::Admin";
-  else if (owl_message_is_type_generic(m)) blessas = "owl::Message::Generic";
-  else                                     blessas = "owl::Message";
+  if (owl_message_is_type_zephyr(m))       blessas = "BarnOwl::Message::Zephyr";
+  else if (owl_message_is_type_aim(m))     blessas = "BarnOwl::Message::AIM";
+  else if (owl_message_is_type_jabber(m))  blessas = "BarnOwl::Message::Jabber";
+  else if (owl_message_is_type_admin(m))   blessas = "BarnOwl::Message::Admin";
+  else if (owl_message_is_type_generic(m)) blessas = "BarnOwl::Message::Generic";
+  else                                     blessas = "BarnOwl::Message";
 
   hr = sv_2mortal(newRV_noinc((SV*)h));
@@ -255,19 +255,19 @@
 
   /* create legacy variables */
-  perl_get_sv("owl::id", TRUE);
-  perl_get_sv("owl::class", TRUE);
-  perl_get_sv("owl::instance", TRUE);
-  perl_get_sv("owl::recipient", TRUE);
-  perl_get_sv("owl::sender", TRUE);
-  perl_get_sv("owl::realm", TRUE);
-  perl_get_sv("owl::opcode", TRUE);
-  perl_get_sv("owl::zsig", TRUE);
-  perl_get_sv("owl::msg", TRUE);
-  perl_get_sv("owl::time", TRUE);
-  perl_get_sv("owl::host", TRUE);
-  perl_get_av("owl::fields", TRUE);
+  perl_get_sv("BarnOwl::id", TRUE);
+  perl_get_sv("BarnOwl::class", TRUE);
+  perl_get_sv("BarnOwl::instance", TRUE);
+  perl_get_sv("BarnOwl::recipient", TRUE);
+  perl_get_sv("BarnOwl::sender", TRUE);
+  perl_get_sv("BarnOwl::realm", TRUE);
+  perl_get_sv("BarnOwl::opcode", TRUE);
+  perl_get_sv("BarnOwl::zsig", TRUE);
+  perl_get_sv("BarnOwl::msg", TRUE);
+  perl_get_sv("BarnOwl::time", TRUE);
+  perl_get_sv("BarnOwl::host", TRUE);
+  perl_get_av("BarnOwl::fields", TRUE);
 
   if(file) {
-    SV * cfg = get_sv("owl::configfile", TRUE);
+    SV * cfg = get_sv("BarnOwl::configfile", TRUE);
     sv_setpv(cfg, file);
   }
@@ -283,5 +283,5 @@
 
   /* check if we have the formatting function */
-  if (owl_perlconfig_is_function("owl::format_msg")) {
+  if (owl_perlconfig_is_function("BarnOwl::format_msg")) {
     owl_global_set_config_format(&g, 1);
   }
@@ -361,5 +361,5 @@
     char *ret = NULL;
     ret = owl_perlconfig_call_with_message(subname?subname
-					   :"owl::_format_msg_legacy_wrap", m);
+					   :"BarnOwl::_format_msg_legacy_wrap", m);
     if (!ret) {
       ret = owl_sprintf("@b([Perl Message Formatting Failed!])\n");
@@ -368,7 +368,7 @@
   } else {
     char *ptr = NULL;
-    if (owl_perlconfig_is_function("owl::receive_msg")) {
+    if (owl_perlconfig_is_function("BarnOwl::Hooks::receive_msg")) {
       ptr = owl_perlconfig_call_with_message(subname?subname
-				       :"owl::_receive_msg_legacy_wrap", m);
+				       :"BarnOwl::_receive_msg_legacy_wrap", m);
     }
     if (ptr) owl_free(ptr);
@@ -452,7 +452,9 @@
 void owl_perlconfig_mainloop()
 {
+  if (!owl_perlconfig_is_function("BarnOwl::Hooks::mainloop_hook"))
+    return;
   dSP ;
   PUSHMARK(SP) ;
-  call_pv("owl::mainloop_hook", G_DISCARD|G_EVAL);
+  call_pv("BarnOwl::Hooks::mainloop_hook", G_DISCARD|G_EVAL);
   if(SvTRUE(ERRSV)) {
     STRLEN n_a;
Index: perlglue.xs
===================================================================
--- perlglue.xs	(revision 17eed9c47adbe937e400caf93acbf9315b5a2828)
+++ perlglue.xs	(revision 8203afdd0879526e14674b39e741493894354216)
@@ -13,5 +13,5 @@
 #define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV)
 
-MODULE = owl		PACKAGE = owl		
+MODULE = BarnOwl		PACKAGE = BarnOwl		
 
 char *
Index: perlwrap.pm
===================================================================
--- perlwrap.pm	(revision 3354cea596fd4b1fdc82f5d68c1831049c5121b7)
+++ perlwrap.pm	(revision 8203afdd0879526e14674b39e741493894354216)
@@ -9,10 +9,11 @@
 use warnings;
 
-package owl;
+package BarnOwl;
 
 
 BEGIN {
 # bootstrap in C bindings and glue
-    bootstrap owl 1.2;
+    *owl:: = \*BarnOwl::;
+    bootstrap BarnOwl 1.2;
 };
 
@@ -28,5 +29,5 @@
     my ($m) = @_;
     $m->legacy_populate_global();
-    return &owl::format_msg($m);
+    return &BarnOwl::format_msg($m);
 }
 
@@ -35,8 +36,8 @@
     my ($m) = @_;
     $m->legacy_populate_global();
-    return &owl::receive_msg($m);
-}
-
-# make owl::<command>("foo") be aliases to owl::command("<command> foo");
+    return &BarnOwl::Hooks::receive_msg($m);
+}
+
+# make BarnOwl::<command>("foo") be aliases to BarnOwl::command("<command> foo");
 sub AUTOLOAD {
     our $AUTOLOAD;
@@ -44,5 +45,5 @@
     $called =~ s/.*:://;
     $called =~ s/_/-/g;
-    return &owl::command("$called ".join(" ",@_));
+    return &BarnOwl::command("$called ".join(" ",@_));
 }
 
@@ -70,11 +71,11 @@
 
     no warnings 'uninitialized';
-    owl::new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description});
-}
-
-#####################################################################
-#####################################################################
-
-package owl::Message;
+    BarnOwl::new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description});
+}
+
+#####################################################################
+#####################################################################
+
+package BarnOwl::Message;
 
 sub new {
@@ -82,5 +83,5 @@
     my %args = (@_);
     if($class eq __PACKAGE__ && $args{type}) {
-        $class = "owl::Message::" . ucfirst $args{type};
+        $class = "BarnOwl::Message::" . ucfirst $args{type};
     }
     return bless {%args}, $class;
@@ -137,10 +138,10 @@
 sub delete {
     my ($m) = @_;
-    &owl::command("delete --id ".$m->id);
+    &BarnOwl::command("delete --id ".$m->id);
 }
 
 sub undelete {
     my ($m) = @_;
-    &owl::command("undelete --id ".$m->id);
+    &BarnOwl::command("undelete --id ".$m->id);
 }
 
@@ -169,24 +170,24 @@
 sub legacy_populate_global {
     my ($m) = @_;
-    $owl::direction  = $m->direction ;
-    $owl::type       = $m->type      ;
-    $owl::id         = $m->id        ;
-    $owl::class      = $m->class     ;
-    $owl::instance   = $m->instance  ;
-    $owl::recipient  = $m->recipient ;
-    $owl::sender     = $m->sender    ;
-    $owl::realm      = $m->realm     ;
-    $owl::opcode     = $m->opcode    ;
-    $owl::zsig       = $m->zsig      ;
-    $owl::msg        = $m->body      ;
-    $owl::time       = $m->time      ;
-    $owl::host       = $m->host      ;
-    $owl::login      = $m->login     ;
-    $owl::auth       = $m->auth      ;
+    $BarnOwl::direction  = $m->direction ;
+    $BarnOwl::type       = $m->type      ;
+    $BarnOwl::id         = $m->id        ;
+    $BarnOwl::class      = $m->class     ;
+    $BarnOwl::instance   = $m->instance  ;
+    $BarnOwl::recipient  = $m->recipient ;
+    $BarnOwl::sender     = $m->sender    ;
+    $BarnOwl::realm      = $m->realm     ;
+    $BarnOwl::opcode     = $m->opcode    ;
+    $BarnOwl::zsig       = $m->zsig      ;
+    $BarnOwl::msg        = $m->body      ;
+    $BarnOwl::time       = $m->time      ;
+    $BarnOwl::host       = $m->host      ;
+    $BarnOwl::login      = $m->login     ;
+    $BarnOwl::auth       = $m->auth      ;
     if ($m->fields) {
-	@owl::fields = @{$m->fields};
+	@BarnOwl::fields = @{$m->fields};
 	@main::fields = @{$m->fields};
     } else {
-	@owl::fields = undef;
+	@BarnOwl::fields = undef;
 	@main::fields = undef;
     }
@@ -200,7 +201,7 @@
 #####################################################################
 
-package owl::Message::Admin;
-
-use base qw( owl::Message );
+package BarnOwl::Message::Admin;
+
+use base qw( BarnOwl::Message );
 
 sub header       { return shift->{"header"}; }
@@ -209,14 +210,14 @@
 #####################################################################
 
-package owl::Message::Generic;
-
-use base qw( owl::Message );
-
-#####################################################################
-#####################################################################
-
-package owl::Message::AIM;
-
-use base qw( owl::Message );
+package BarnOwl::Message::Generic;
+
+use base qw( BarnOwl::Message );
+
+#####################################################################
+#####################################################################
+
+package BarnOwl::Message::AIM;
+
+use base qw( BarnOwl::Message );
 
 # all non-loginout AIM messages are personal for now...
@@ -228,7 +229,7 @@
 #####################################################################
 
-package owl::Message::Zephyr;
-
-use base qw( owl::Message );
+package BarnOwl::Message::Zephyr;
+
+use base qw( BarnOwl::Message );
 
 sub login_tty { 
@@ -263,5 +264,5 @@
     my ($m) = @_;
     my $sender = $m->sender;
-    my $realm = owl::zephyr_getrealm();
+    my $realm = BarnOwl::zephyr_getrealm();
     $sender =~ s/\@$realm$//;
     return $sender;
@@ -285,4 +286,86 @@
 package owl;
 
+################################################################################
+# Mainloop hook
+################################################################################
+
+our $shutdown;
+$shutdown = 0;
+our $reload;
+$reload = 0;
+
+#Run this on start and reload. Adds modules
+sub onStart
+{
+    reload_init();
+    loadModules();
+}
+################################################################################
+# Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl
+################################################################################
+sub reload_hook (@)
+{
+    BarnOwl::Hooks::startup();
+    return 1;
+}
+
+sub reload
+{
+    # Use $reload to tell modules that we're performing a reload.
+  {
+      local $reload = 1;
+      BarnOwl::mainloop_hook();
+  }
+    
+  @BarnOwl::Hooks::onMainLoop = ();
+  @BarnOwl::Hooks::onStartSubs = ();
+
+  # Do reload
+  package main;
+  if (do "$ENV{HOME}/.owlconf" && BarnOwl::reload_hook(@_))
+  {
+      return "owlconf reloaded";
+  } 
+  else
+  {
+      return "$ENV{HOME}/.owlconf load attempted, but error encountered:\n$@";
+  }
+  package owl;
+}
+
+sub reload_init () 
+{
+    BarnOwl::command('alias reload perl BarnOwl::reload()');
+    BarnOwl::command('bindkey global "C-x C-r" command reload');
+}
+
+################################################################################
+# Loads modules from ~/.owl/modules and owl's data directory
+################################################################################
+
+sub loadModules () {
+    my @modules;
+    my $rv;
+    foreach my $dir ( BarnOwl::get_data_dir() . "/modules",
+                      $ENV{HOME} . "/.owl/modules" )
+    {
+        opendir( MODULES, $dir );
+
+        # source ./modules/*.pl
+        @modules = grep( /\.pl$/, readdir(MODULES) );
+
+        foreach my $mod (@modules) {
+            owl::error("Loading $dir/$mod...");
+            unless ($rv = do "$dir/$mod") {
+                BarnOwl::error("Couldn't load $dir/$mod:\n $@") if $@;
+                BarnOwl::error("Couldn't run $dir/$mod:\n $!") unless defined $rv;
+            }
+        }
+        closedir(MODULES);
+    }
+}
+
+package BarnOwl::Hooks;
+
 # Arrays of subrefs to be called at specific times.
 our @onStartSubs = ();
@@ -291,13 +374,4 @@
 our @onGetBuddyList = ();
 
-################################################################################
-# Mainloop hook
-################################################################################
-
-our $shutdown;
-$shutdown = 0;
-our $reload;
-$reload = 0;
-
 # Functions to call hook lists
 sub runHook($@)
@@ -315,9 +389,4 @@
 }
 
-sub mainloop_hook
-{
-    runHook(\@onMainLoop);
-}
-
 ################################################################################
 # Startup and Shutdown code
@@ -325,23 +394,7 @@
 sub startup
 {
-# Modern versions of owl provides a great place to have startup stuff.
-# Put things in ~/.owl/startup
-    onStart();
-}
-
-sub shutdown
-{
-# Modern versions of owl provides a great place to have shutdown stuff.
-# Put things in ~/.owl/shutdown
-
-    # use $shutdown to tell modules that that's what we're doing.
-    $shutdown = 1;
-    mainloop_hook();
-}
-
-#Run this on start and reload. Adds modules and runs their startup functions.
-sub onStart
-{
-    reload_init();
+    # Modern versions of owl provides a great place to have startup stuff.
+    # Put things in ~/.owl/startup
+
     #So that the user's .owlconf can have startsubs, we don't clear
     #onStartSubs; reload does however
@@ -350,70 +403,28 @@
     @onGetBuddyList = ();
 
-    loadModules();
+    BarnOwl::onStart();
+
     runHook(\@onStartSubs);
-}
-################################################################################
-# Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl
-################################################################################
-sub reload_hook (@)
-{
-    onStart();
-    return 1;
-}
-
-sub reload
-{
-    # Use $reload to tell modules that we're performing a reload.
-    $reload = 1;
-    owl::mainloop_hook();
-    $reload = 0;
-    @onMainLoop = ();
-    @onStartSubs = ();
-
-    # Do reload
-    package main;
-    if (do "$ENV{HOME}/.owlconf" && owl::reload_hook(@_))
-    {
-        return "owlconf reloaded";
-    } 
-    else
-    {
-        return "$ENV{HOME}/.owlconf load attempted, but error encountered:\n$@";
-    }
-    package owl;
-}
-
-sub reload_init () 
-{
-    owl::command('alias reload perl owl::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;
-    my $rv;
-    foreach my $dir ( owl::get_data_dir() . "/modules",
-                      $ENV{HOME} . "/.owl/modules" )
-    {
-        opendir( MODULES, $dir );
-
-        # source ./modules/*.pl
-        @modules = grep( /\.pl$/, readdir(MODULES) );
-
-        foreach my $mod (@modules) {
-            unless ($rv = do "$dir/$mod") {
-                owl::error("Couldn't load $dir/$mod:\n $@") if $@;
-                owl::error("Couldn't run $dir/$mod:\n $!") unless defined $rv;
-            }
-        }
-        closedir(MODULES);
-    }
-}
-
-
+
+    BarnOwl::startup() if *BarnOwl::startup{CODE};
+}
+
+sub shutdown
+{
+# Modern versions of owl provides a great place to have shutdown stuff.
+# Put things in ~/.owl/shutdown
+
+    # use $shutdown to tell modules that that's what we're doing.
+    $BarnOwl::shutdown = 1;
+    BarnOwl::mainloop_hook();
+
+    BarnOwl::shutdown() if *BarnOwl::shutdown{CODE};
+}
+
+sub mainloop_hook
+{
+    runHook(\@onMainLoop);
+    BarnOwl::mainlook_hook() if *BarnOwl::mainloop_hook{CODE};
+}
 
 ################################################################################
@@ -425,4 +436,5 @@
     my $m = shift;
     runHook(\@onReceiveMsg, $m);
+    BarnOwl::receive_msg($m) if *BarnOwl::receive_msg{CODE};
 }
 
@@ -433,6 +445,5 @@
 sub get_blist
 {
-    my $m = shift;
-    return runHook_accumulate(\@onGetBuddyList, $m);
+    return runHook_accumulate(\@onGetBuddyList);
 }
 
@@ -446,12 +457,13 @@
                           onMainLoop
                           onGetBuddyList ) {
-        *{"main::".$hook} = \*{"owl::".$hook};
+        *{"main::".$hook} = \*{"BarnOwl::Hooks::".$hook};
+        *{"owl::".$hook} = \*{"BarnOwl::Hooks::".$hook};
     }
 }
 
 # load the config  file
-if (-r $owl::configfile) {
+if (-r $BarnOwl::configfile) {
     undef $@;
-    do $owl::configfile;
+    do $BarnOwl::configfile;
     die $@ if $@;
 }
