Changeset 338e5235f0585384ca0db9d54211b880de159b37

Show
Ignore:
Timestamp:
10/28/09 22:49:10 (4 weeks ago)
Author:
Nelson Elhage <nelhage@mit.edu>
git-author:
Nelson Elhage <nelhage@mit.edu> / 2009-10-27T23:52:55Z-0400
Parents:
7ca5d3e3f8c76c75f3200773de375d80ac951461
git-committer:
Nelson Elhage <nelhage@mit.edu> / 2009-10-28T22:49:10Z-0400
Message:
Some work towards composable/customizable styles.

Replace most direct method calls on message objects with calls to
methods on the style that (by default) just delegate to the object.

This allows for subclasses to override these methods to customize the
display. With the use of the C3 mro (use mro 'c3'; in perl 5.10) in
subclasses, this even allows for subclasses to be composed with each
other by making a subclass with multiple parent classes.
Location:
perl/lib/BarnOwl/Style
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl/Style/Default.pm

    r0b2afba r338e523  
    3939################################################################################ 
    4040 
     41BEGIN { 
     42    for my $field qw(body 
     43                     context subcontext 
     44                     personal_context short_personal_context 
     45                     login login_type login_extra 
     46                     pretty_sender long_sender 
     47                     pretty_recipient ) { 
     48        no strict 'refs'; 
     49        *{"BarnOwl::Style::Default::$field"} = sub { 
     50            my $self = shift; 
     51            my $m = shift; 
     52            return $m->$field; 
     53        } 
     54    } 
     55}; 
     56 
    4157sub format_time { 
    4258    my $self = shift; 
     
    5167    return sprintf( 
    5268        '@b<%s%s> for @b(%s) (%s) %s', 
    53         uc( $m->login ), 
    54         $m->login_type, 
    55         $m->pretty_sender, 
    56         $m->login_extra, 
     69        uc( $self->login($m) ), 
     70        $self->login_type($m), 
     71        $self->pretty_sender($m), 
     72        $self->login_extra($m), 
    5773        $self->format_time($m) 
    5874       ); 
     
    6278    my $self = shift; 
    6379    my $m = shift; 
    64     my $personal_context = $m->personal_context; 
     80    my $personal_context = $self->personal_context($m); 
    6581    $personal_context = ' [' . $personal_context . ']' if $personal_context; 
    66     return "\@b(PING)" . $personal_context . " from \@b(" . $m->pretty_sender . ")"; 
     82    return "\@b(PING)" . $personal_context . " from \@b(" . $self->pretty_sender($m) . ")"; 
    6783} 
    6884 
     
    85101    my $header; 
    86102    if ( $m->is_personal ) { 
    87         my $personal_context = $m->personal_context; 
     103        my $personal_context = $self->personal_context($m); 
    88104        $personal_context = ' [' . $personal_context . ']' if $personal_context; 
    89105 
    90106        if ( $m->direction eq "out" ) { 
    91             $header = ucfirst $m->type . $personal_context . " sent to " . $m->pretty_recipient; 
     107            $header = ucfirst $m->type . $personal_context . " sent to " . $self->pretty_recipient($m); 
    92108        } else { 
    93             $header = ucfirst $m->type . $personal_context . " from " . $m->pretty_sender; 
     109            $header = ucfirst $m->type . $personal_context . " from " . $self->pretty_sender($m); 
    94110        } 
    95111    } else { 
    96         $header = $m->context; 
    97         if(defined $m->subcontext) { 
    98             $header .= ' / ' . $m->subcontext; 
     112        $header = $self->context($m); 
     113        if(defined $self->subcontext($m)) { 
     114            $header .= ' / ' . $self->subcontext($m); 
    99115        } 
    100         $header .= ' / @b{' . $m->pretty_sender . '}'; 
     116        $header .= ' / @b{' . $self->pretty_sender($m) . '}'; 
    101117    } 
    102118 
     
    112128    my $self = shift; 
    113129    my $m = shift; 
    114     my $sender = $m->long_sender; 
     130    my $sender = $self->long_sender($m); 
    115131    $sender =~ s/\n.*$//s; 
    116132    if (BarnOwl::getvar('colorztext') eq 'on') { 
     
    126142    my $m = shift; 
    127143 
    128     my $body = $m->body; 
     144    my $body = $self->body($m); 
    129145    if ($m->{should_wordwrap}) { 
    130146      $body = BarnOwl::wordwrap($body, BarnOwl::getnumcols()-9); 
  • perl/lib/BarnOwl/Style/OneLine.pm

    rfc92548d r338e523  
    2626    '<', 
    2727    $m->type, 
    28     uc( $m->login ), 
    29     $m->pretty_sender) 
    30     . ($m->login_extra ? "at ".$m->login_extra : ''); 
     28    uc( $self->login(m) ), 
     29    $self->pretty_sender($m)) 
     30    . ($self->login_extra($m) ? "at ".$self->login_extra($m) : ''); 
    3131} 
    3232 
     
    3939    $m->type, 
    4040    'PING', 
    41     $m->pretty_sender) 
     41    $self->pretty_sender($m)) 
    4242} 
    4343 
     
    6262                   $dirsym, 
    6363                   $m->type, 
    64                    maybe($m->short_personal_context), 
     64                   maybe($self->short_personal_context($m)), 
    6565                   ($dir eq 'out' 
    66                     ? $m->pretty_recipient 
    67                     : $m->pretty_sender)); 
     66                    ? $self->pretty_recipient($m) 
     67                    : $self->pretty_sender($m))); 
    6868  } 
    6969  else { 
    7070    $line = sprintf(BASE_FORMAT, 
    7171                    $dirsym, 
    72                     maybe($m->context), 
    73                     maybe($m->subcontext), 
     72                    maybe($self->context($m)), 
     73                    maybe($self->subcontext($m)), 
    7474                    ($dir eq 'out' 
    75                      ? $m->pretty_recipient 
    76                      : $m->pretty_sender)); 
     75                     ? $self->pretty_recipient($m) 
     76                     : $self->pretty_sender($m))); 
    7777  } 
    7878 
    79   my $body = $m->{body}; 
     79  my $body = $self->body($m); 
    8080  $body =~ tr/\n/ /; 
    8181  $line .= $body; 
     
    8989  my $m = shift; 
    9090  my $line = sprintf(BASE_FORMAT, '<', 'ADMIN', '', ''); 
    91   my $body = $m->{body}; 
     91  my $body = $self->body($m); 
    9292  $body =~ tr/\n/ /; 
    9393  return $line.$body;