/[suikacvs]/messaging/manakai/lib/Message/Util/Formatter/Text.pm
Suika

Contents of /messaging/manakai/lib/Message/Util/Formatter/Text.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Mon Dec 1 07:50:14 2003 UTC (22 years, 8 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +9 -5 lines
Support of boolean attribute

1 wakaba 1.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 wakaba 1.3 our $VERSION = do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
19 wakaba 1.1 require Message::Util::Formatter::Base;
20     our @ISA = 'Message::Util::Formatter::Base';
21    
22     sub rule_def () {+{
23     -bare_text => {
24 wakaba 1.2 after => sub {
25 wakaba 1.1 my ($self, $name, $p, $o, $key => $val) = @_;
26 wakaba 1.2 $p->{-result} .= $p->{-bare_text};
27 wakaba 1.1 },
28     },
29     -undef => {
30     post => sub {
31     my ($self, $name, $p, $o) = @_;
32 wakaba 1.2 $p->{-result} = qq([undef: $name]);
33 wakaba 1.1 },
34     },
35     -default => {
36     pre => sub {
37     my ($self, $name, $p, $o, %opt) = @_;
38 wakaba 1.2 $p->{-result} = '';
39 wakaba 1.1 $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 wakaba 1.2 if (length $p->{-result} and
45 wakaba 1.1 (defined $p->{prefix} or defined $p->{suffix})) {
46 wakaba 1.2 $p->{-result} = $p->{prefix} . $p->{-result} . $p->{suffix};
47 wakaba 1.1 }
48     },
49     attr => sub {
50     my ($self, $name, $p, $o, $key, $val, %opt) = @_;
51 wakaba 1.3 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 wakaba 1.1 }
59     },
60     before => sub {
61     },
62     after => sub {
63     },
64     },
65     -entire => {
66     pre => sub {
67     my ($self, $name, $p, $o) = @_;
68 wakaba 1.2 $p->{-result} = '';
69 wakaba 1.1 },
70     attr => sub {
71     my ($self, $name, $p, $o, $key => $val) = @_;
72 wakaba 1.2 $p->{-result} .= $val->{-result};
73 wakaba 1.1 },
74     },
75     percent => {
76     after => sub {
77     my ($self, $name, $p, $o) = @_;
78 wakaba 1.2 $p->{-result} = '%';
79 wakaba 1.1 },
80     },
81     }}
82    
83     sub new ($;%) {
84     my ($class, %opt) = @_;
85     my $rule = $opt{rule};
86     $opt{rule} = sub {
87     $_[0]->rule_def->{$_[1]}
88     or
89     __PACKAGE__->rule_def->{$_[1]}
90     };
91     $class->SUPER::new (%opt);
92     }
93    
94     =head1 LICENSE
95    
96     Copyright 2003 Wakaba <[email protected]>
97    
98     This program is free software; you can redistribute it and/or
99     modify it under the same terms as Perl itself.
100    
101     =cut
102    
103 wakaba 1.3 1; # $Date: 2003/11/16 11:44:16 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24