| 1 |
wakaba |
1.1 |
|
| 2 |
|
|
=head1 NAME
|
| 3 |
|
|
|
| 4 |
|
|
Message::Util::Formatter::Node --- Manakai : Generating Node tree with formatting rule
|
| 5 |
|
|
|
| 6 |
|
|
=head1 DESCRIPTION
|
| 7 |
|
|
|
| 8 |
|
|
This module is an application of Message::Util::Formatter mechanism,
|
| 9 |
|
|
used to generate a node tree (fragment) with given formatting
|
| 10 |
|
|
rule text and formatting functions.
|
| 11 |
|
|
|
| 12 |
|
|
Although this module is intended to be used in combination with
|
| 13 |
|
|
Message::Markup::XML::Node, it can be useful as a base class for
|
| 14 |
|
|
other node module interface.
|
| 15 |
|
|
|
| 16 |
|
|
This module is part of manakai.
|
| 17 |
|
|
|
| 18 |
|
|
=cut
|
| 19 |
|
|
|
| 20 |
|
|
package Message::Util::Formatter::Node;
|
| 21 |
|
|
use strict;
|
| 22 |
wakaba |
1.3 |
our $VERSION = do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
|
| 23 |
wakaba |
1.1 |
require Message::Util::Formatter::Base;
|
| 24 |
|
|
our @ISA = 'Message::Util::Formatter::Base';
|
| 25 |
|
|
|
| 26 |
wakaba |
1.3 |
sub ___rule_def () {+{
|
| 27 |
wakaba |
1.1 |
-attr_bare_text => {
|
| 28 |
|
|
main => sub {
|
| 29 |
|
|
my ($self, $name, $p, $o, %opt) = @_;
|
| 30 |
wakaba |
1.2 |
return ref $opt{-parent} ?
|
| 31 |
|
|
$opt{-parent}->append_text ($opt{-attr_bare_text})
|
| 32 |
|
|
: $opt{-class}->new (type => '#text',
|
| 33 |
|
|
value => $opt{-attr_bare_text});
|
| 34 |
wakaba |
1.1 |
},
|
| 35 |
|
|
},
|
| 36 |
|
|
-bare_text => {
|
| 37 |
|
|
main => sub {
|
| 38 |
|
|
my ($self, $name, $p, $o, %opt) = @_;
|
| 39 |
|
|
return $p->{-parent}->append_text ($p->{-bare_text});
|
| 40 |
|
|
},
|
| 41 |
|
|
},
|
| 42 |
|
|
-undef => {
|
| 43 |
|
|
main => sub {
|
| 44 |
|
|
my ($self, $name, $p, $o) = @_;
|
| 45 |
|
|
$p->{-parent}->append_text ("[undef: $name]");
|
| 46 |
|
|
},
|
| 47 |
|
|
},
|
| 48 |
|
|
-default => {
|
| 49 |
|
|
pre => sub {
|
| 50 |
wakaba |
1.2 |
# my ($self, $name, $p, $o, %opt) = @_;
|
| 51 |
|
|
# local $p->{-parent} = $o->{-result};
|
| 52 |
wakaba |
1.1 |
},
|
| 53 |
|
|
post => sub {
|
| 54 |
|
|
my ($self, $name, $p, $o, %opt) = @_;
|
| 55 |
|
|
local $p->{-parent} = $o->{-result};
|
| 56 |
|
|
$self->call ($name, 'main', $p, $o, %opt);
|
| 57 |
|
|
},
|
| 58 |
|
|
attr => sub {
|
| 59 |
|
|
my ($self, $name, $p, $o, $key, $val, %opt) = @_;
|
| 60 |
wakaba |
1.2 |
if ($key eq '-boolean') {
|
| 61 |
|
|
$p->{$val} = 1;
|
| 62 |
|
|
} else {
|
| 63 |
|
|
if ($opt{-value_flag} and index ($opt{-value_flag}, 'p') > -1) {
|
| 64 |
|
|
$p->{-parse_flag}->{$key} = 1;
|
| 65 |
|
|
}
|
| 66 |
|
|
$p->{$key} = $val;
|
| 67 |
wakaba |
1.1 |
}
|
| 68 |
|
|
},
|
| 69 |
|
|
main => sub {
|
| 70 |
|
|
},
|
| 71 |
|
|
},
|
| 72 |
|
|
-entire => {
|
| 73 |
|
|
pre => sub {
|
| 74 |
|
|
my ($self, $name, $p, $o, %opt) = @_;
|
| 75 |
|
|
if (ref $opt{option}->{-parent}) {
|
| 76 |
|
|
$o->{-result} = $opt{option}->{-parent};
|
| 77 |
|
|
} else {
|
| 78 |
|
|
$o->{-result} = $opt{option}->{-class}->new
|
| 79 |
|
|
(type => '#fragment');
|
| 80 |
|
|
}
|
| 81 |
|
|
},
|
| 82 |
|
|
post => sub {
|
| 83 |
|
|
},
|
| 84 |
|
|
attr => sub {
|
| 85 |
|
|
},
|
| 86 |
|
|
},
|
| 87 |
|
|
percent => {
|
| 88 |
|
|
main => sub {
|
| 89 |
|
|
my ($self, $name, $p, $o) = @_;
|
| 90 |
|
|
$p->{-parent}->append_text ('%');
|
| 91 |
|
|
},
|
| 92 |
|
|
},
|
| 93 |
|
|
}}
|
| 94 |
|
|
|
| 95 |
|
|
sub parse_attr ($$$$;%) {
|
| 96 |
|
|
my ($self, $p, $name, $o, %opt) = @_;
|
| 97 |
wakaba |
1.2 |
if ($p->{-parse_flag}->{$name} > 0) {
|
| 98 |
|
|
$p->{-parse_flag}->{$name} = -1;
|
| 99 |
|
|
$p->{$name} = $self->replace ($p->{$name},
|
| 100 |
|
|
%{$opt{option}}, param => $o,
|
| 101 |
|
|
-parent => $opt{-parent});
|
| 102 |
|
|
} elsif ($p->{-parse_flag}->{$name} < 0) {
|
| 103 |
|
|
$p->{$name};
|
| 104 |
wakaba |
1.1 |
} elsif ($opt{-non_parsed_to_node}) {
|
| 105 |
wakaba |
1.2 |
$p->{$name} = $self->call (-attr_bare_text => 'main', $p, $o,
|
| 106 |
|
|
%{$opt{option}},
|
| 107 |
|
|
-attr_bare_text => $p->{$name},
|
| 108 |
|
|
-parent => $opt{-parent});
|
| 109 |
|
|
} else {
|
| 110 |
|
|
undef;
|
| 111 |
wakaba |
1.1 |
}
|
| 112 |
|
|
}
|
| 113 |
|
|
|
| 114 |
|
|
=head1 LICENSE
|
| 115 |
|
|
|
| 116 |
|
|
Copyright 2003 Wakaba <[email protected]>
|
| 117 |
|
|
|
| 118 |
|
|
This program is free software; you can redistribute it and/or
|
| 119 |
|
|
modify it under the same terms as Perl itself.
|
| 120 |
|
|
|
| 121 |
|
|
=cut
|
| 122 |
|
|
|
| 123 |
wakaba |
1.3 |
1; # $Date: 2003/12/01 07:50:29 $
|