Changeset 338e5235f0585384ca0db9d54211b880de159b37
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r0b2afba
|
r338e523
|
|
| 39 | 39 | ################################################################################ |
| 40 | 40 | |
| | 41 | BEGIN { |
| | 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 | |
| 41 | 57 | sub format_time { |
| 42 | 58 | my $self = shift; |
| … |
… |
|
| 51 | 67 | return sprintf( |
| 52 | 68 | '@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), |
| 57 | 73 | $self->format_time($m) |
| 58 | 74 | ); |
| … |
… |
|
| 62 | 78 | my $self = shift; |
| 63 | 79 | my $m = shift; |
| 64 | | my $personal_context = $m->personal_context; |
| | 80 | my $personal_context = $self->personal_context($m); |
| 65 | 81 | $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) . ")"; |
| 67 | 83 | } |
| 68 | 84 | |
| … |
… |
|
| 85 | 101 | my $header; |
| 86 | 102 | if ( $m->is_personal ) { |
| 87 | | my $personal_context = $m->personal_context; |
| | 103 | my $personal_context = $self->personal_context($m); |
| 88 | 104 | $personal_context = ' [' . $personal_context . ']' if $personal_context; |
| 89 | 105 | |
| 90 | 106 | 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); |
| 92 | 108 | } else { |
| 93 | | $header = ucfirst $m->type . $personal_context . " from " . $m->pretty_sender; |
| | 109 | $header = ucfirst $m->type . $personal_context . " from " . $self->pretty_sender($m); |
| 94 | 110 | } |
| 95 | 111 | } 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); |
| 99 | 115 | } |
| 100 | | $header .= ' / @b{' . $m->pretty_sender . '}'; |
| | 116 | $header .= ' / @b{' . $self->pretty_sender($m) . '}'; |
| 101 | 117 | } |
| 102 | 118 | |
| … |
… |
|
| 112 | 128 | my $self = shift; |
| 113 | 129 | my $m = shift; |
| 114 | | my $sender = $m->long_sender; |
| | 130 | my $sender = $self->long_sender($m); |
| 115 | 131 | $sender =~ s/\n.*$//s; |
| 116 | 132 | if (BarnOwl::getvar('colorztext') eq 'on') { |
| … |
… |
|
| 126 | 142 | my $m = shift; |
| 127 | 143 | |
| 128 | | my $body = $m->body; |
| | 144 | my $body = $self->body($m); |
| 129 | 145 | if ($m->{should_wordwrap}) { |
| 130 | 146 | $body = BarnOwl::wordwrap($body, BarnOwl::getnumcols()-9); |
-
|
rfc92548d
|
r338e523
|
|
| 26 | 26 | '<', |
| 27 | 27 | $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) : ''); |
| 31 | 31 | } |
| 32 | 32 | |
| … |
… |
|
| 39 | 39 | $m->type, |
| 40 | 40 | 'PING', |
| 41 | | $m->pretty_sender) |
| | 41 | $self->pretty_sender($m)) |
| 42 | 42 | } |
| 43 | 43 | |
| … |
… |
|
| 62 | 62 | $dirsym, |
| 63 | 63 | $m->type, |
| 64 | | maybe($m->short_personal_context), |
| | 64 | maybe($self->short_personal_context($m)), |
| 65 | 65 | ($dir eq 'out' |
| 66 | | ? $m->pretty_recipient |
| 67 | | : $m->pretty_sender)); |
| | 66 | ? $self->pretty_recipient($m) |
| | 67 | : $self->pretty_sender($m))); |
| 68 | 68 | } |
| 69 | 69 | else { |
| 70 | 70 | $line = sprintf(BASE_FORMAT, |
| 71 | 71 | $dirsym, |
| 72 | | maybe($m->context), |
| 73 | | maybe($m->subcontext), |
| | 72 | maybe($self->context($m)), |
| | 73 | maybe($self->subcontext($m)), |
| 74 | 74 | ($dir eq 'out' |
| 75 | | ? $m->pretty_recipient |
| 76 | | : $m->pretty_sender)); |
| | 75 | ? $self->pretty_recipient($m) |
| | 76 | : $self->pretty_sender($m))); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | | my $body = $m->{body}; |
| | 79 | my $body = $self->body($m); |
| 80 | 80 | $body =~ tr/\n/ /; |
| 81 | 81 | $line .= $body; |
| … |
… |
|
| 89 | 89 | my $m = shift; |
| 90 | 90 | my $line = sprintf(BASE_FORMAT, '<', 'ADMIN', '', ''); |
| 91 | | my $body = $m->{body}; |
| | 91 | my $body = $self->body($m); |
| 92 | 92 | $body =~ tr/\n/ /; |
| 93 | 93 | return $line.$body; |