| 1 |
|
| 2 |
=head1 NAME
|
| 3 |
|
| 4 |
Message::Util::Formatter::Text --- Manakai : Plain-text formatter
|
| 5 |
|
| 6 |
=head1 DESCRIPTION
|
| 7 |
|
| 8 |
This module is an application of Message::Util::Formatter mechanism,
|
| 9 |
used to generate formatted plain text (fragment) with given formatting
|
| 10 |
rule text and formatting functions.
|
| 11 |
|
| 12 |
This module is part of manakai.
|
| 13 |
|
| 14 |
=cut
|
| 15 |
|
| 16 |
package Message::Util::Formatter::Text;
|
| 17 |
use strict;
|
| 18 |
our $VERSION = do{my @r=(q$Revision: 1.4 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
|
| 19 |
require Message::Util::Formatter::Base;
|
| 20 |
our @ISA = 'Message::Util::Formatter::Base';
|
| 21 |
|
| 22 |
sub ___rule_def () {+{
|
| 23 |
-bare_text => {
|
| 24 |
after => sub {
|
| 25 |
my ($self, $name, $p, $o, $key => $val) = @_;
|
| 26 |
$p->{-result} .= $p->{-bare_text};
|
| 27 |
},
|
| 28 |
},
|
| 29 |
-undef => {
|
| 30 |
post => sub {
|
| 31 |
my ($self, $name, $p, $o) = @_;
|
| 32 |
$p->{-result} = qq([undef: $name]);
|
| 33 |
},
|
| 34 |
},
|
| 35 |
-default => {
|
| 36 |
pre => sub {
|
| 37 |
my ($self, $name, $p, $o, %opt) = @_;
|
| 38 |
$p->{-result} = '';
|
| 39 |
$self->call ($name, 'before', $p, $o, %opt);
|
| 40 |
},
|
| 41 |
post => sub {
|
| 42 |
my ($self, $name, $p, $o, %opt) = @_;
|
| 43 |
$self->call ($name, 'after', $p, $o, %opt);
|
| 44 |
if (length $p->{-result}) {
|
| 45 |
$p->{-result} = $p->{prefix} . $p->{-result} if defined $p->{prefix};
|
| 46 |
$p->{-result} .= $p->{suffix} if defined $p->{suffix};
|
| 47 |
}
|
| 48 |
},
|
| 49 |
attr => sub {
|
| 50 |
my ($self, $name, $p, $o, $key, $val, %opt) = @_;
|
| 51 |
if ($key eq '-boolean') {
|
| 52 |
$p->{$val} = 1;
|
| 53 |
} else {
|
| 54 |
if ($opt{-value_flag} and index ($opt{-value_flag}, 'p') > -1) {
|
| 55 |
$val = $self->replace ($val, param => $o);
|
| 56 |
}
|
| 57 |
$p->{$key} = $val;
|
| 58 |
}
|
| 59 |
},
|
| 60 |
before => sub {
|
| 61 |
},
|
| 62 |
after => sub {
|
| 63 |
},
|
| 64 |
},
|
| 65 |
-entire => {
|
| 66 |
pre => sub {
|
| 67 |
my ($self, $name, $p, $o) = @_;
|
| 68 |
$p->{-result} = '';
|
| 69 |
},
|
| 70 |
attr => sub {
|
| 71 |
my ($self, $name, $p, $o, $key => $val) = @_;
|
| 72 |
$p->{-result} .= $val->{-result};
|
| 73 |
},
|
| 74 |
},
|
| 75 |
percent => {
|
| 76 |
after => sub {
|
| 77 |
my ($self, $name, $p, $o) = @_;
|
| 78 |
$p->{-result} = '%';
|
| 79 |
},
|
| 80 |
},
|
| 81 |
}}
|
| 82 |
|
| 83 |
=head1 LICENSE
|
| 84 |
|
| 85 |
Copyright 2003 Wakaba <w@suika.fam.cx>
|
| 86 |
|
| 87 |
This program is free software; you can redistribute it and/or
|
| 88 |
modify it under the same terms as Perl itself.
|
| 89 |
|
| 90 |
=cut
|
| 91 |
|
| 92 |
1; # $Date: 2003/12/06 05:09:39 $
|