summaryrefslogtreecommitdiff
path: root/fml/doc/ja/tutorial/module
diff options
context:
space:
mode:
authorfukachan <fukachan>2003-03-09 08:29:08 +0000
committerfukachan <fukachan>2003-03-09 08:29:08 +0000
commit670cfb4d0b2abc942517a1d706349ba81697f498 (patch)
treece6057bc112b2edfc7eeb8604f6081fe3ecc0c2a /fml/doc/ja/tutorial/module
parentc62651a5a1cac63e14d7c186c9c1433f84c6c97d (diff)
downloadfml8-670cfb4d0b2abc942517a1d706349ba81697f498.tar.gz
fml8-670cfb4d0b2abc942517a1d706349ba81697f498.tar.bz2
fml8-670cfb4d0b2abc942517a1d706349ba81697f498.zip
merge 01_* with tutorial/
Diffstat (limited to 'fml/doc/ja/tutorial/module')
-rw-r--r--fml/doc/ja/tutorial/module/encode.sgml123
1 files changed, 123 insertions, 0 deletions
diff --git a/fml/doc/ja/tutorial/module/encode.sgml b/fml/doc/ja/tutorial/module/encode.sgml
new file mode 100644
index 00000000..42e7e346
--- /dev/null
+++ b/fml/doc/ja/tutorial/module/encode.sgml
@@ -0,0 +1,123 @@
+<chapter id="module.mail.message.encode">
+ <title>
+ Mail::Message::Encode クラス
+ </title>
+
+<para>
+[リファレンス]
+fml-help ML's Count: 02012, 02013, 02016 など
+</para>
+
+<screen>
+[使い方の例]
+
+ use Mail::Message::Encode;
+ my $encode = new Mail::Message::Encode;
+ my $str_euc = $encode->convert( $s, 'euc-jp' );
+ my $str_euc = $encode->convert( $s, 'euc-jp', 'iso-2022-jp' );
+
+ my $encode = new Mail::Message::Encode;
+ my $status = $encode->convert_str_ref( \$s, 'euc-jp' );
+ my $status = $encode->convert_str_ref( \$s, 'euc-jp', 'jis' );
+
+ my $fp = sub { ... };
+ $encode->run_in_chcode( $fp, $oout, $in );
+
+ * 4.0 互換
+ ues Mail::Message::Encode qw(STR2EUC);
+ my $euc_s = STR2EUC( $s );
+</screen>
+
+
+<sect1>
+ <title>
+ 仕様
+ </title>
+
+<para>
+本体は _convert_str_ref() にまとめる。
+
+<screen>
+ sub convert # 引数が STR
+ {
+ my ($self, $str, $out_code, $in_code) = @_;
+ _convert_str_ref(\$str, $out, $in);
+
+ return $str;
+ }
+
+
+ sub convert_str_ref # 引数が STR_REF
+ {
+ my ($self, $str, $out, $in) = @_;
+ _convert_str_ref($str, $out, $in);
+ }
+
+
+ sub _convert_str_ref # 引数が STR_REF
+ {
+ my ($str, $out, $in) = @_;
+
+ # 1. 推測
+ もし $in がない → 推測 → 失敗 → 0 をかえす?
+
+ # 2. 変換をトライ
+ if ($in がわかった or $in が指定された) {
+ $out へ変換
+ jcode, Jcode, Encode は perl バージョンによって
+ よろしく変換をがんばる
+ return 1 ; #成功
+ }
+ else { # principle of least surprise ?
+ なにもしない# str はそのまま返す
+ }
+
+ return 0 ; # 失敗
+ }
+</screen>
+
+<screen>
+ sub base64 {}
+ sub quoted_printable {}
+
+ があるといいかな〜
+
+ $x = $encode->base64($s);
+</screen>
+
+また、互換性というか便宜上、STR2XXX() も準備する。
+<screen>
+ STR2EUC( $str, [$icode] )
+ STR2JIS( $str, [$icode] )
+ STR2SJIS( $str, [$icode] )
+</screen>
+は convert_str_ref を wrap する。
+</para>
+
+</sect1>
+
+
+<sect1>
+ <title>
+ 特別な関数
+ </title>
+
+<para>
+euc にしてごにょごにょ する典型的なコードは全部 wrap する。
+<screen>
+# change code and do $proc
+sub run_in_chcode
+{
+ my ($self, $proc, $s, $out_code, $in_code) = @_;
+
+ my $conv_status = convert_str_ref($s, $EUC_JP, $in_code);
+ my $proc_status = &$proc($s, @_);
+ convert_str_ref($s, $out_code, $EUC_JP) if $conv_status && $out_code;
+ return wantarray ? ($conv_status, $proc_status): $conv_status;
+}
+</screen>
+</para>
+
+</sect1>
+
+</chapter>