<html xmlns="http://www.w3.org/1999/xhtml" a0:Name="SuikaWiki" xmlns:a0="urn:x-suika-fam-cx:markup:suikawiki:0:9:" a0:Version="0.9"><head></head><body><p><a0:anchor-end a0:anchor="1">[1]</a0:anchor-end> <a0:anchor>manakai</a0:anchor> のモジュール群 <code class="perl">Message::Util::Formatter</code>
<a0:anchor-external a0:resParameter="SuikaCVS:&quot;messaging/manakai/lib/Message/Util/Formatter/&quot;" a0:resScheme="IW">IW:SuikaCVS:&quot;messaging/manakai/lib/Message/Util/Formatter/&quot;</a0:anchor-external>
は、雛形と引数から結果を得るための汎用モジュールです。</p><p>たとえば、雛形 <samp>%year (digit =&gt; 4, zone =&gt; {+09:00});-%month (zone =&gt; {+09:00});-%date (zone =&gt; {+09:00});</samp>
と現在時刻から日付を得る (ように構成する) ことができます。</p><p><a0:anchor-end a0:anchor="5">[5]</a0:anchor-end> <code class="perl">Message::Util::Formatter</code> という名前のモジュールは既に
obsolete です。当分は互換性のために manakai の一部として配布されますが、
このモジュール自体は使わないでください。</p><p>代わりに、 <code class="perl">Message::Util::Formatter::<var>*</var></code>
というモジュール群が用意されています。<ul><li><code class="perl"><a0:anchor>Message::Util::Formatter::Base</a0:anchor></code>:
雛形を解釈し、処理する手続きを呼び出す処理を実装した基底級です。
通常は、このモジュールを直接扱う必要はありませんが、
このモジュールを継承して処理に特化したモジュールを作成することもできます。</li><li><code class="perl"><a0:anchor>Message::Util::Formatter::Text</a0:anchor></code>:
雛形から結果として文字列を得るためのモジュールです。</li><li><code class="perl"><a0:anchor>Message::Util::Formatter::Node</a0:anchor></code>:
雛形から結果として木構造を得るためのモジュールです。
このモジュールは、 <code class="perl"><a0:anchor>Message::Markup::XML::Node</a0:anchor></code>
といっしょに使うことを想定しています (たとえば、 <samp>append_new_node</samp> メソッドを使います)。
他の木構造を扱うモジュールを使うときには、 <code class="perl">Message::Util::Formatter::Node</code> を参考に別途モジュールを作成する必要があります。</li><li><code class="perl"><a0:anchor>Message::Util::Formatter::Boolean</a0:anchor></code>:
雛形から結果として真偽値を得るためのモジュールです。
真または偽または不明 (<code class="perl"><a0:anchor>undef</a0:anchor></code>) を扱うことができます。</li></ul></p><section><h1>雛形の書式</h1><p><a0:anchor-end a0:anchor="6">[6]</a0:anchor-end> <code class="perl">Message::Util::Formatter::<var>*</var></code> に与える雛形の書式を、
<dfn><code class="perl">Message::Util::Formatter</code> 形式</dfn>などと呼んでいます。
<a0:weak>もっと短くて分かりやすくて格好良い名前があったら教えてください!</a0:weak></p><p>詳しくは <code class="WikiPage"><a0:anchor>Message::Util::Formatter//書式</a0:anchor></code>を見てください。</p></section><section><h1>結果を得る</h1><p><a0:anchor-end a0:anchor="7">[7]</a0:anchor-end> <code class="perl">Message::Util::Formatter</code> で雛形から結果を得るには、<pre>require <var>formatter-module</var>;
my $formatter = <var>formatter-module</var>-&gt;new (%option);

$result1 = $formatter-&gt;replace ($template1, %option1);
$result2 = $formatter-&gt;replace ($template2, %option2);</pre><p>のようにしてください。</p></p></section><section><h1>書式付けモジュールの作成</h1><ed xmlns="urn:x-suika-fam-cx:markup:suikawiki:0:10:">TBD</ed></section><section><h1>歴史</h1><p><a0:anchor-end a0:anchor="2">[2]</a0:anchor-end> もともと、 <code class="perl"><a0:anchor>Message::Field::Date</a0:anchor></code> で任意の書式で日付を出力するために <code class="perl">Message:Util::Formatter</code> モジュールが書かれました。</p><p>その後、 <a0:anchor>SuikaWiki</a0:anchor> (2) で <a0:anchor>WikiForm</a0:anchor> を記述するための書式として採用されました。
更に、 <a0:anchor>WikiView</a0:anchor> など、 SuikaWiki 全体に渡って
<code class="perl">Message::Util::Formatter</code>
が使われるようになりましたが、その際に、 <a0:anchor>XML</a0:anchor>
のような木構造を扱うために、出力を単純な文字列ではなく、
Perl の物体にできるようになりました。</p><p><a0:anchor-end a0:anchor="3">[3]</a0:anchor-end> このような建て増しの結果 <code class="perl">Message::Util::Formatter</code>
は柔軟な扱いができなくなってしまいましたので、
新たに <code class="perl">Message::Util::Formatter::Base</code>
とその派生級に再構成されました。
新しい構成では、文字列を得るための
<code class="perl">Message::Util::Formatter::Text</code>,
木構造を得るための <code class="perl">Message::Util::Formatter::Node</code>,
論理値を得るための <code class="perl">Message::Util::Formatter::Boolean</code>
が用意され、必要に応じて使い分けることができます。
また、以上のいずれかのモジュールを基底としてより特化したモジュールを実装することもできます。</p></section><section><h1>メモ</h1></section></body></html>