Index: Makefile.in
===================================================================
--- Makefile.in	(revision d5ebf3a23f1c487dd0185e06f2f09e0bca6ef101)
+++ Makefile.in	(revision 864ed359c1c6fbc341ca8d3a273cb7c2ae4e0875)
@@ -25,5 +25,5 @@
      regex.c history.c view.c dict.c variable.c filterelement.c pair.c \
      keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \
-     aim.c buddy.c buddylist.c timer.c style.c stylefunc.c errqueue.c \
+     aim.c buddy.c buddylist.c timer.c style.c errqueue.c \
      zbuddylist.c muxevents.c popexec.c obarray.c select.c
 OWL_SRC = owl.c
Index: commands.c
===================================================================
--- commands.c	(revision d768834c77a446ab144927c65b4bb758dcdf4c1e)
+++ commands.c	(revision 864ed359c1c6fbc341ca8d3a273cb7c2ae4e0875)
@@ -101,12 +101,4 @@
 	      "Use 'show keymaps' to see the existing keymaps.\n"
 	      "Key sequences may be things like M-C-t or NPAGE.\n"),
-
-  OWLCMD_ARGS("style", owl_command_style, OWL_CTX_ANY,
-	      "creates a new style",
-	      "style <name> perl <function_name>",
-	      "Creates a new style for formatting messages.\n"
-	      "A style named <name> will be created that will\n"
-	      "format messages using the perl function <function_name>.\n\n"
-	      "SEE ALSO: show styles, view -s, filter -s\n"),
 
   OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
@@ -1675,25 +1667,4 @@
   return NULL;
 }
-
-char *owl_command_style(int argc, char **argv, char *buff) {
-  owl_style *s;
-
-  /* Usage: style <name> perl <function> */
-  if (argc != 4 || strcmp(argv[2], "perl")) {
-    owl_function_makemsg("Usage: style <name> perl <function>");
-    return NULL;
-  }
-  if (!owl_perlconfig_is_function(argv[3])) {
-    owl_function_makemsg("Unable to create style '%s': no perl function '%s'",
-			 argv[1], argv[3]);
-    return NULL;
-  }
-  s=owl_malloc(sizeof(owl_style));
-  owl_style_create_perl(s, argv[1], argv[3], NULL);
-  owl_global_add_style(&g, s);
-
-  return NULL;
-}
-
 
 void owl_command_quit()
Index: owl.c
===================================================================
--- owl.c	(revision c0c4449c0a92972db3612cd8487b9d6fa50eba1a)
+++ owl.c	(revision 864ed359c1c6fbc341ca8d3a273cb7c2ae4e0875)
@@ -265,11 +265,4 @@
   }
 
-  /* setup the built-in styles */
-  owl_function_debugmsg("startup: creating built-in styles");
-
-  s=owl_malloc(sizeof(owl_style));
-  owl_style_create_internal(s, "basic", &owl_stylefunc_basic, "Basic message formatting.");
-  owl_global_add_style(&g, s);
-
   /* setup the default filters */
   /* the personal filter will need to change again when AIM chat's are
Index: perlglue.xs
===================================================================
--- perlglue.xs	(revision 9c7a701363179369d764454b0d99e559ab89ed9e)
+++ perlglue.xs	(revision 864ed359c1c6fbc341ca8d3a273cb7c2ae4e0875)
@@ -256,8 +256,7 @@
 
 void
-_create_style(name, function, description)
+_create_style(name, object)
      char *name
-     char *function
-     char *description
+     SV  *object
      PREINIT:
 		/* This is to allow us to bootstrap the default style before the
@@ -267,5 +266,5 @@
 	{
 		s = owl_malloc(sizeof(owl_style));
-		owl_style_create_perl(s, name, function, description);
+		owl_style_create_perl(s, name, object);
 		owl_global_add_style(&g, s);
 	}
Index: perlwrap.pm
===================================================================
--- perlwrap.pm	(revision 9815e2e0d63da9ec80cf2cd49d34c9ae896f1967)
+++ perlwrap.pm	(revision 864ed359c1c6fbc341ca8d3a273cb7c2ae4e0875)
@@ -702,8 +702,8 @@
         if(*BarnOwl::format_msg{CODE}) {
             # if the config defines a legacy formatting function, add 'perl' as a style 
-            BarnOwl::_create_style("perl", "BarnOwl::_format_msg_legacy_wrap",
-                                   "User-defined perl style that calls BarnOwl::format_msg"
-                                   . " with legacy global variable support");
-            BarnOwl::set("-q default_style perl");
+            # BarnOwl::_create_style("perl", "BarnOwl::_format_msg_legacy_wrap",
+            #                        "User-defined perl style that calls BarnOwl::format_msg"
+            #                        . " with legacy global variable support");
+            # BarnOwl::set("-q default_style perl");
         }
     }
@@ -763,18 +763,21 @@
 sub format_message($)
 {
+    my $self = shift;
     my $m = shift;
 
     if ( $m->is_loginout) {
-        return format_login($m);
+        return $self->format_login($m);
     } elsif($m->is_ping && $m->is_personal) {
-        return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" );
+        return $self->format_ping($m);
     } elsif($m->is_admin) {
-        return "\@bold(OWL ADMIN)\n" . indentBody($m);
+        return $self->format_admin($m);
     } else {
-        return format_chat($m);
+        return $self->format_chat($m);
     }
 }
 
-BarnOwl::_create_style("default", "BarnOwl::Style::Default::format_message", "Default style");
+sub description {"Default style";}
+
+BarnOwl::_create_style("default", "BarnOwl::Style::Default");
 
 ################################################################################
@@ -787,4 +790,5 @@
 
 sub format_login($) {
+    my $self = shift;
     my $m = shift;
     return sprintf(
@@ -798,5 +802,18 @@
 }
 
+sub format_ping {
+    my $self = shift;
+    my $m = shift;
+    return "\@b(PING) from \@b(" . $m->pretty_sender . ")\n";
+}
+
+sub format_admin {
+    my $self = shift;
+    my $m = shift;
+    return "\@bold(OWL ADMIN)\n" . indentBody($m);
+}
+
 sub format_chat($) {
+    my $self = shift;
     my $m = shift;
     my $header;
@@ -846,4 +863,12 @@
 }
 
+package BarnOwl::Style::Basic;
+
+our @ISA=qw(BarnOwl::Style::Default);
+
+sub description {"Compatability alias for the default style";}
+
+BarnOwl::_create_style("basic", "BarnOwl::Style::Basic");
+
 package BarnOwl::Style::OneLine;
 ################################################################################
@@ -852,28 +877,29 @@
 use constant BASE_FORMAT => '%s %-13.13s %-11.11s %-12.12s ';
 sub format_message($) {
+  my $self = shift;
   my $m = shift;
 
-#  if ( $m->is_zephyr ) {
-#    return format_zephyr($m);
-#  }
   if ( $m->is_loginout ) {
-    return format_login($m);
+    return $self->format_login($m);
   }
   elsif ( $m->is_ping) {
-    return format_ping($m);
+    return $self->format_ping($m);
   }
   elsif ( $m->is_admin || $m->is_loopback) {
-    return format_local($m);
+    return $self->format_local($m);
   }
   else {
-    return format_chat($m);
+    return $self->format_chat($m);
   }
 }
 
-BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine::format_message", "Formats for one-line-per-message");
+sub description {"Formats for one-line-per-message"}
+
+BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine");
 
 ################################################################################
 
 sub format_login($) {
+  my $self = shift;
   my $m = shift;
   return sprintf(
@@ -898,4 +924,5 @@
 sub format_chat($)
 {
+  my $self = shift;
   my $m = shift;
   my $dir = lc($m->{direction});
@@ -938,4 +965,5 @@
 sub format_local($)
 {
+  my $self = shift;
   my $m = shift;
   my $type = uc($m->{type});
Index: style.c
===================================================================
--- style.c	(revision 5a9f6fe47907e20e155786f4bd2ccfc8cb0b0782)
+++ style.c	(revision 864ed359c1c6fbc341ca8d3a273cb7c2ae4e0875)
@@ -1,31 +1,11 @@
+#define OWL_PERL
 #include "owl.h"
 
 static const char fileIdent[] = "$Id$";
 
-void owl_style_create_internal(owl_style *s, char *name, void (*formatfunc) (owl_fmtext *fm, owl_message *m), char *description)
+void owl_style_create_perl(owl_style *s, char *name, SV *obj)
 {
-  s->type=OWL_STYLE_TYPE_INTERNAL;
   s->name=owl_strdup(name);
-  if (description) {
-    s->description=owl_strdup(description);
-  } else {
-    s->description=owl_sprintf("Owl internal style %s", name);
-  }
-  s->perlfuncname=NULL;
-  s->formatfunc=formatfunc;
-}
-
-void owl_style_create_perl(owl_style *s, char *name, char *perlfuncname, char *description)
-{
-  s->type=OWL_STYLE_TYPE_PERL;
-  s->name=owl_strdup(name);
-  s->perlfuncname=owl_strdup(perlfuncname);
-  if (description) {
-    s->description=owl_strdup(description);
-  } else {
-    s->description=owl_sprintf("User-defined perl style that calls %s", 
-			       perlfuncname);
-  }
-  s->formatfunc=NULL;
+  s->perlobj = SvREFCNT_inc(obj);
 }
 
@@ -43,5 +23,17 @@
 char *owl_style_get_description(owl_style *s)
 {
-  return(s->description);
+  SV *sv = NULL;
+  OWL_PERL_CALL_METHOD(s->perlobj,
+                       "description",
+                       /* no args */,
+                       "Error in style_get_description: %s",
+                       0,
+                       sv = SvREFCNT_inc(POPs);
+                       );
+  if(sv) {
+    return SvPV_nolen(sv_2mortal(sv));
+  } else {
+    return "[error getting description]";
+  }
 }
 
@@ -51,46 +43,46 @@
 void owl_style_get_formattext(owl_style *s, owl_fmtext *fm, owl_message *m)
 {
-  if (s->type==OWL_STYLE_TYPE_INTERNAL) {
-    (* s->formatfunc)(fm, m);
-  } else if (s->type==OWL_STYLE_TYPE_PERL) {
-    char *body, *indent;
-    int curlen;
+  char *body, *indent;
+  int curlen;
 
-    /* run the perl function */
-    body=owl_perlconfig_getmsg(m, 1, s->perlfuncname);
-    if (!strcmp(body, "")) {
-      owl_free(body);
-      body=owl_strdup("<unformatted message>");
-    }
-    
-    /* indent and ensure ends with a newline */
-    indent=owl_malloc(strlen(body)+(owl_text_num_lines(body))*OWL_TAB+10);
-    owl_text_indent(indent, body, OWL_TAB);
-    curlen = strlen(indent);
-    if (curlen==0 || indent[curlen-1] != '\n') {
-      indent[curlen] = '\n';
-      indent[curlen+1] = '\0';
-    }
+  SV *sv = NULL;
+  
+  /* Call the perl object */
+  OWL_PERL_CALL_METHOD(s->perlobj,
+                       "format_message",
+                       XPUSHs(owl_perlconfig_message2hashref(m));,
+                       "Error in format_message: %s",
+                       0,
+                       sv = SvREFCNT_inc(POPs);
+                       );
 
-    /* fmtext_append.  This needs to change */
-    owl_fmtext_append_ztext(fm, indent);
-    
-    owl_free(indent);
-    owl_free(body);
+  if(sv) {
+    body = SvPV_nolen(sv);
+  } else {
+    body = "<unformatted message>";
   }
+
+  /* indent and ensure ends with a newline */
+  indent=owl_malloc(strlen(body)+(owl_text_num_lines(body))*OWL_TAB+10);
+  owl_text_indent(indent, body, OWL_TAB);
+  curlen = strlen(indent);
+  if (curlen==0 || indent[curlen-1] != '\n') {
+    indent[curlen] = '\n';
+    indent[curlen+1] = '\0';
+  }
+
+  /* fmtext_append.  This needs to change */
+  owl_fmtext_append_ztext(fm, indent);
+
+  owl_free(indent);
+  if(sv)
+    SvREFCNT_dec(body);
 }
 
 int owl_style_validate(owl_style *s) {
-  if (!s) {
-    return -1;
-  } else if (s->type==OWL_STYLE_TYPE_INTERNAL) {
-    return 0;
-  } else if (s->type==OWL_STYLE_TYPE_PERL 
-	     && s->perlfuncname 
-	     && owl_perlconfig_is_function(s->perlfuncname)) {
-    return 0;
-  } else {
+  if (!s || !s->perlobj || !SvOK(s->perlobj)) {
     return -1;
   }
+  return 0;
 }
 
@@ -98,7 +90,4 @@
 {
   if (s->name) owl_free(s->name);
-  if (s->description) owl_free(s->description);
-  if (s->type==OWL_STYLE_TYPE_PERL && s->perlfuncname) {
-    owl_free(s->perlfuncname);
-  }
+  SvREFCNT_dec(s->perlobj);
 }
Index: ylefunc.c
===================================================================
--- stylefunc.c	(revision f2d72128d54fe0a3466422505e2ae01e3b137498)
+++ 	(revision )
@@ -1,221 +1,0 @@
-#include "owl.h"
-
-static const char fileIdent[] = "$Id$";
-
-/* In all of these functions, 'fm' is expected to already be
- * initialized.
- */
-
-void owl_style_basic_format_body(owl_fmtext *fm, owl_message *m) {
-  char *indent, *body;
-  owl_filter *f;
-  int wrap = 0;
-
-  /* get the body */
-  body=owl_strdup(owl_message_get_body(m));
-
-  f = owl_global_get_filter(&g, "wordwrap");
-  if(f && owl_filter_message_match(f, m)) 
-    wrap = 1;
-
-  if(wrap) {
-    int cols, i, width, word;
-    char *tab, *tok, *ws = " \t\n\r";
-    cols = owl_global_get_cols(&g) - OWL_MSGTAB - 1;
-
-    tab = owl_malloc(OWL_MSGTAB+1);
-    for(i = 0; i < OWL_MSGTAB; i++) {
-      tab[i] = ' ';
-    }
-    tab[OWL_MSGTAB] = 0;
-
-    tok = strtok(body, ws);
-    tab[OWL_MSGTAB-1] = 0;
-    owl_fmtext_append_normal(fm, tab);
-    tab[OWL_MSGTAB-1] = ' ';
-    width = 0;
-
-    while(tok) {
-      word = strlen(tok);
-      if(word + width + 1 < cols) {
-        owl_fmtext_append_normal(fm, " ");
-        owl_fmtext_append_normal(fm, tok);
-        width += word + 1;
-      } else {
-        owl_fmtext_append_normal(fm, "\n");
-        owl_fmtext_append_normal(fm, tab);
-        owl_fmtext_append_normal(fm, tok);
-        width = word;
-      }
-      tok = strtok(NULL, ws);
-    }
-    owl_fmtext_append_normal(fm, "\n");
-
-    owl_free(tab);
-  } else {
-    /* do the indenting into indent */
-    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
-    owl_text_indent(indent, body, OWL_MSGTAB);
-    owl_fmtext_append_ztext(fm, indent);
-    if(body[strlen(body)-1] != '\n')
-      owl_fmtext_append_ztext(fm, "\n");
-    owl_free(indent);
-  }
-
-  owl_free(body);
-}
- 
-void owl_stylefunc_basic(owl_fmtext *fm, owl_message *m)
-{
-#ifdef HAVE_LIBZEPHYR
-  char *ptr, *zsigbuff, frombuff[LINE];
-  ZNotice_t *n;
-#endif
-
-  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
-#ifdef HAVE_LIBZEPHYR
-    n=owl_message_get_notice(m);
-  
-    /* edit the from addr for printing */
-    strcpy(frombuff, owl_message_get_sender(m));
-    ptr=strchr(frombuff, '@');
-    if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
-      *ptr='\0';
-    }
-    
-    /* set the message for printing */
-    owl_fmtext_append_normal(fm, OWL_TABSTR);
-    
-    if (owl_message_is_ping(m)) {
-      owl_fmtext_append_bold(fm, "PING");
-      owl_fmtext_append_normal(fm, " from ");
-      owl_fmtext_append_bold(fm, frombuff);
-      owl_fmtext_append_normal(fm, "\n");
-    } else if (owl_message_is_loginout(m)) {
-      char *host, *tty;
-
-      host=owl_message_get_attribute_value(m, "loginhost");
-      tty=owl_message_get_attribute_value(m, "logintty");
-      
-      if (owl_message_is_login(m)) {
-	owl_fmtext_append_bold(fm, "LOGIN");
-      } else if (owl_message_is_logout(m)) {
-	owl_fmtext_append_bold(fm, "LOGOUT");
-      }
-      if (owl_message_is_pseudo(m)) {
-	owl_fmtext_append_bold(fm, " (PSEUDO)");
-      }
-      owl_fmtext_append_normal(fm, " for ");
-      ptr=short_zuser(owl_message_get_instance(m));
-      owl_fmtext_append_bold(fm, ptr);
-      owl_free(ptr);
-      owl_fmtext_append_normal(fm, " at ");
-      owl_fmtext_append_normal(fm, host ? host : "");
-      owl_fmtext_append_normal(fm, " ");
-      owl_fmtext_append_normal(fm, tty ? tty : "");
-      owl_fmtext_append_normal(fm, "\n");
-    } else {
-      owl_fmtext_append_normal(fm, "From: ");
-      if (strcasecmp(owl_message_get_class(m), "message")) {
-	owl_fmtext_append_normal(fm, "Class ");
-	owl_fmtext_append_normal(fm, owl_message_get_class(m));
-	owl_fmtext_append_normal(fm, " / Instance ");
-	owl_fmtext_append_normal(fm, owl_message_get_instance(m));
-	owl_fmtext_append_normal(fm, " / ");
-      }
-      owl_fmtext_append_normal(fm, frombuff);
-      if (strcasecmp(owl_message_get_realm(m), owl_zephyr_get_realm())) {
-	owl_fmtext_append_normal(fm, " {");
-	owl_fmtext_append_normal(fm, owl_message_get_realm(m));
-	owl_fmtext_append_normal(fm, "} ");
-      }
-      
-      /* stick on the zsig */
-      zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
-      owl_message_pretty_zsig(m, zsigbuff);
-      owl_fmtext_append_normal(fm, "    (");
-      owl_fmtext_append_ztext(fm, zsigbuff);
-      owl_fmtext_append_normal(fm, ")");
-      owl_fmtext_append_normal(fm, "\n");
-      owl_free(zsigbuff);
-      
-      /* then the indented message */
-      owl_style_basic_format_body(fm, m);
-      
-      /* make personal messages bold for smaat users */
-      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
-	if (owl_message_is_personal(m)) {
-	  owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
-	}
-      }
-    }
-    
-#endif
-  } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) {
-    char *zsigbuff, *foo;
-    owl_fmtext_append_normal(fm, OWL_TABSTR);
-    owl_fmtext_append_normal(fm, "To: ");
-    foo=short_zuser(owl_message_get_recipient(m));
-    owl_fmtext_append_normal(fm, foo);
-    owl_free(foo);
-    owl_fmtext_append_normal(fm, "  (Zsig: ");
-    
-    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
-    owl_message_pretty_zsig(m, zsigbuff);
-    owl_fmtext_append_ztext(fm, zsigbuff);
-    owl_free(zsigbuff);
-    
-    owl_fmtext_append_normal(fm, ")");
-    owl_fmtext_append_normal(fm, "\n");
-    owl_style_basic_format_body(fm, m);
-  } else if (owl_message_is_type_aim(m)) {
-    if (owl_message_is_loginout(m)) {
-      owl_fmtext_append_normal(fm, OWL_TABSTR);
-      if (owl_message_is_login(m)) {
-	owl_fmtext_append_bold(fm, "AIM LOGIN");
-      } else {
-	owl_fmtext_append_bold(fm, "AIM LOGOUT");
-      }
-      owl_fmtext_append_normal(fm, " for ");
-      owl_fmtext_append_normal(fm, owl_message_get_sender(m));
-      owl_fmtext_append_normal(fm, "\n");
-    } else if (owl_message_is_direction_in(m)) {
-      owl_fmtext_append_bold(fm, OWL_TABSTR);
-      owl_fmtext_append_bold(fm, "AIM from ");
-      owl_fmtext_append_bold(fm, owl_message_get_sender(m));
-      owl_fmtext_append_bold(fm, "\n");
-      owl_style_basic_format_body(fm, m);
-    } else if (owl_message_is_direction_out(m)) {
-      owl_fmtext_append_normal(fm, OWL_TABSTR);
-      owl_fmtext_append_normal(fm, "AIM sent to ");
-      owl_fmtext_append_normal(fm, owl_message_get_recipient(m));
-      owl_fmtext_append_normal(fm, "\n");
-      owl_style_basic_format_body(fm, m);
-    }
-  } else if (owl_message_is_type_admin(m)) {
-    char *text, *header;
-    
-    text=owl_message_get_body(m);
-    header=owl_message_get_attribute_value(m, "adminheader");
-
-    owl_fmtext_append_normal(fm, OWL_TABSTR);
-    owl_fmtext_append_bold(fm, "OWL ADMIN ");
-    owl_fmtext_append_ztext(fm, header);
-    owl_fmtext_append_normal(fm, "\n");
-    owl_style_basic_format_body(fm, m);
-  } else {
-    char *header;
-
-    header=owl_sprintf("%s from: %s to: %s",
-		       owl_message_get_type(m),
-		       owl_message_get_sender(m),
-		       owl_message_get_recipient(m));
-
-    owl_fmtext_append_normal(fm, OWL_TABSTR);
-    owl_fmtext_append_normal(fm, header);
-    owl_fmtext_append_normal(fm, "\n");
-    owl_style_basic_format_body(fm, m);
-    
-    owl_free(header);
-  }
-}
