Changeset b67ab6b


Ignore:
Timestamp:
Apr 29, 2008, 1:21:15 AM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
52f8dd6
Parents:
864ed35
Message:
Implement back-compat with old-style owl::format_msg() styles
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    r864ed35 rb67ab6b  
    589589  if(owl_message_is_direction_in(m)) {
    590590    /* let perl know about it*/
    591     owl_perlconfig_getmsg(m, 0, NULL);
     591    owl_perlconfig_getmsg(m, NULL);
    592592
    593593    /* do we need to autoreply? */
  • perlconfig.c

    r9c7a701 rb67ab6b  
    411411}
    412412
    413 char *owl_perlconfig_getmsg(owl_message *m, int mode, char *subname)
    414 {
    415   /* if mode==1 we are doing message formatting.  The returned
    416    * formatted message needs to be freed by the caller.
    417    *
    418    * if mode==0 we are just doing the message-has-been-received
    419    * thing.
    420    */
    421   if (!owl_global_have_config(&g)) return(NULL);
    422  
    423   /* run the procedure corresponding to the mode */
    424   if (mode==1) {
    425     char *ret = NULL;
    426     ret = owl_perlconfig_call_with_message(subname?subname
    427                                            :"BarnOwl::_format_msg_legacy_wrap", m);
    428     if (!ret) {
    429       ret = owl_sprintf("@b([Perl Message Formatting Failed!])\n");
    430     }
    431     return ret;
    432   } else {
    433     char *ptr = NULL;
    434     if (owl_perlconfig_is_function("BarnOwl::Hooks::_receive_msg")) {
    435       ptr = owl_perlconfig_call_with_message(subname?subname
    436                                        :"BarnOwl::_receive_msg_legacy_wrap", m);
    437     }
    438     if (ptr) owl_free(ptr);
    439     return(NULL);
    440   }
     413void owl_perlconfig_getmsg(owl_message *m, char *subname)
     414{
     415  char *ptr = NULL;
     416  if (owl_perlconfig_is_function("BarnOwl::Hooks::_receive_msg")) {
     417    ptr = owl_perlconfig_call_with_message(subname?subname
     418                                           :"BarnOwl::_receive_msg_legacy_wrap", m);
     419  }
     420  if (ptr) owl_free(ptr);
    441421}
    442422
  • perlglue.xs

    r864ed35 rb67ab6b  
    256256
    257257void
    258 _create_style(name, object)
     258create_style(name, object)
    259259     char *name
    260260     SV  *object
    261261     PREINIT:
    262                 /* This is to allow us to bootstrap the default style before the
    263                 command architecture has been initialized */
    264262                owl_style *s;
    265263     CODE:
  • perlwrap.pm

    r864ed35 rb67ab6b  
    153153}
    154154$configfile ||= $ENV{HOME}."/.owlconf";
    155 
    156 # populate global variable space for legacy owlconf files
    157 sub _format_msg_legacy_wrap {
    158     my ($m) = @_;
    159     $m->legacy_populate_global();
    160     return &BarnOwl::format_msg($m);
    161 }
    162155
    163156# populate global variable space for legacy owlconf files
     
    702695        if(*BarnOwl::format_msg{CODE}) {
    703696            # if the config defines a legacy formatting function, add 'perl' as a style
    704             # BarnOwl::_create_style("perl", "BarnOwl::_format_msg_legacy_wrap",
    705             #                        "User-defined perl style that calls BarnOwl::format_msg"
    706             #                        . " with legacy global variable support");
    707             # BarnOwl::set("-q default_style perl");
     697            BarnOwl::create_style("perl", BarnOwl::Style::Legacy->new(
     698                "BarnOwl::format_msg",
     699                "User-defined perl style that calls BarnOwl::format_msg"
     700                . " with legacy global variable support",
     701                1));
     702             BarnOwl::set("-q default_style perl");
    708703        }
    709704    }
     
    779774sub description {"Default style";}
    780775
    781 BarnOwl::_create_style("default", "BarnOwl::Style::Default");
     776BarnOwl::create_style("default", "BarnOwl::Style::Default");
    782777
    783778################################################################################
     
    869864sub description {"Compatability alias for the default style";}
    870865
    871 BarnOwl::_create_style("basic", "BarnOwl::Style::Basic");
     866BarnOwl::create_style("basic", "BarnOwl::Style::Basic");
    872867
    873868package BarnOwl::Style::OneLine;
     
    896891sub description {"Formats for one-line-per-message"}
    897892
    898 BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine");
     893BarnOwl::create_style("oneline", "BarnOwl::Style::OneLine");
    899894
    900895################################################################################
     
    996991}
    997992
     993package BarnOwl::Style::Legacy;
     994
     995sub new {
     996    my $class = shift;
     997    my $func  = shift;
     998    my $desc  = shift;
     999    my $useglobals = shift;
     1000    $useglobals = 0 unless defined($useglobals);
     1001    return bless {function    => $func,
     1002                  description => $desc,
     1003                  useglobals  => $useglobals}, $class;
     1004}
     1005
     1006sub description {shift->{description}};
     1007
     1008sub format_message {
     1009    my $self = shift;
     1010    if($self->{useglobals}) {
     1011        $_[0]->legacy_populate_global();
     1012    }
     1013    no strict 'refs';
     1014    goto \&{$self->{function}};
     1015}
     1016
    9981017
    9991018# switch to package main when we're done
Note: See TracChangeset for help on using the changeset viewer.