[perldocjp-cvs 114] CVS update: docs/modules/autobox-Core-0.3

Back to archive index

YAMASHINA Hio hio****@users*****
2006年 11月 2日 (木) 00:52:16 JST


Index: docs/modules/autobox-Core-0.3/Core.pod
diff -u /dev/null docs/modules/autobox-Core-0.3/Core.pod:1.1
--- /dev/null	Thu Nov  2 00:52:16 2006
+++ docs/modules/autobox-Core-0.3/Core.pod	Thu Nov  2 00:52:16 2006
@@ -0,0 +1,749 @@
+
+=encoding utf-8
+
+=head1 名前
+
+autobox::Core - Perl 組み込み関数をプリミティブ型のメソッドに
+
+=head1 概要
+
+  use autobox;
+  use autobox::Core;
+
+  "Hello, World\n"->uc()->print();
+
+=head1 説明
+
+Methods wrapping F<perl>'s built-in functions for minipulating numbers, strings, arrays,
+hashes, and code references. It is handy to use built-in functions as methods to avoid
+messy dereferencing syntaxes and parenthesis pile ups. 
+
+数値, 文字列, 配列, ハッシュ, そしてコードリファレンスを操作する
+F<perl>組み込み関数をラップするメソッド. 厄介なデリファレンス構文や
+括弧の衝突を避けるために組み込み関数をメソッドして利用するのに便利です.
+
+L<autobox> lets you call methods in scalars that aren't object references.
+Numbers, strings, scalars containing numbers, scalars containing strings, 
+array references, hash references, and code references all work as objects.
+L<autobox> adds this feature to L<perl> but does not itself provide any
+methods to call. That is left to the user or another module. For example,
+this module.
+
+L<autobox> はオブジェクトリファレンスではないスカラーに対して
+メソッド呼び出しを提供します. 数値, 文字列, 数値を含んだスカラー, 
+文字列を含んだスカラー, 配列リファレンス, ハッシュリファレンス, 
+そしてコードリファレンス全てオブジェクトとして動作します. 
+L<autobox> は L<perl> にこの機能を提供しますがそれ自身では
+呼び出されるメソッドを何も提供しません. それはユーザやその他の
+モジュールに任されています. そう, 例えば今見ているこのモジュール.
+
+F<autobox::Core> is what you'd call a I<stub> module. It is merely glue, presenting
+existing functions with a new interface. Most of the methods read like
+C<< sub hex ($) { hex($_[0]) } >>.
+Besides built-ins that operate on hashes, arrays, scalars, and code references, 
+some Perl 6-ish things were thrown in, and some keyword like C<foreach> have
+been turned into methods.
+
+F<autobox::Core> はあなたの呼び出す I<スタブ> モジュールです. 
+これは単に接着剤(glue)であり, 既存の関数を新しいインターフェースで
+表現しています. ほとんどの関数は C<< sub hex ($) { hex($_[0]) } >> の
+ように読み取ります. 
+ハッシュ, 配列, スカラー, そしてコードリファレンスを操作する
+ビルトイン関数に加えて, いくつかの Perl 6 的なものも投入されて
+います. そして C<foreach> の様な幾つかのキーワードもメソッドに
+なっています.
+
+=head2 何が実装されているのか
+
+All of the functions listed in L<perldoc> under the headings:
+"Functions for real @ARRAYs",
+"Functions for real %HASHes", 
+"Functions for list data",
+and "Functions for SCALARs or strings", plus a few taken from other sections
+and documented below. 
+Some things expected in Perl 6, such as C<last>, C<elems>, and C<curry>, have been thrown in.
+For use in conjuction with L<Perl6::Contexts>, C<flatten> explicitly flattens an array.
+
+L<perldoc> の中で次の見出しでリストアップされている全ての関数:
+"実際の @ARRAY  に対する関数(Functions for real @ARRAYs)", 
+"実際の %HASH に対する関数(Functions for real %HASHes)", 
+"リストデータに対する関数(Functions for list data)", 
+そして "SCALAR 若しくは文字列に対する関数(Functions for SCALARs or
+strings)", 加えて後述の他の
+セクションやドキュメントから取ってきたいくつか. 
+Perl 6 で予定されている幾つかの事項, C<last>, C<elems>, そして C<curry> 
+が投入されています. L<Perl6::Contexts>, C<flatten> と conjuction して
+使うためには明示的に配列を平坦にする(flatten)する必要があります.
+
+Of the built-in stuff, the things you use most often on data are all implemented. 
+Here's a small sample:
+
+組み込みのものの, データに対してとてもよく使う物は全て実装されています. 
+ちょっとした例:
+
+  print [10, 20, 30, 40, 50]->pop(), "\n";
+  print [10, 20, 30, 40, 50]->shift(), "\n";
+
+  my $arrref = [10, 20, 30];
+
+  my $lala; 
+  $lala = "Lalalalala\n"; print "chomp: ", $lala->chomp(), ' ', $lala, "\n";
+  $lala = "Lalalalala\n"; print "lcfirst: ", $lala->lcfirst(), ' ', $lala, "\n";
+
+  my $hashref = { foo => 10, bar => 20, baz => 30, qux => 40 };
+  print "hash keys: ", join ' ', $hashref->keys(), "\n";
+
+Besides those sections of L<perlfunc>, I've implemented
+C<tie>,
+C<tied>,
+C<ref>,
+C<undef>,
+C<bless>,
+and C<vec>, where they make sense. 
+C<tie>, C<tied>, and C<undef> don't work on code references, and C<bless> doesn't work on non-reference
+scalars.
+C<quotemeta> works on non-reference scalars, along with C<split>, C<m>, and C<s> for regular expression operations.
+
+L<perlfunc> のこれらのセクションの傍で
+C<tie>,
+C<tied>,
+C<ref>,
+C<undef>,
+C<bless>,
+そして C<vec>, をそれらが意味をなすように実装しました. 
+C<tie>, C<tied>, そして C<undef> はコードリファレンスでは動作せず, 
+C<bless> はリファレンスではないスカラーでは動作しません. 
+C<quotemeta> はリファレンスではないスカラーで動作し, 
+正規表現操作は C<split>, C<m>, そして C<s> と共にあります.
+
+  my $arr = [ 1 .. 10 ];
+  $arr->undef;
+
+Array references can tell you how many elements they contain and the index of their last element:
+
+配列リファレンスは何個の要素を持っているかを数えられ, 最後の要素の
+添字を言うことが出来ます.
+
+  my $arr = [ 1 .. 10 ];
+  print '$arr contains ', $arr->size, 
+        ' elements, the last having an index of ', $arr->last, "\n";
+
+Array references have a C<flatten> method to dump their elements.
+This is the same as C<< @{$array_ref} >>.
+
+配列リファレンスはその要素をダンプするために C<flatten> メソッドを
+持っています. これは C<< @{$array_ref} >> と同じです.
+
+  my $arr = [ 1 .. 10 ];
+  print join " -- ", $arr->flatten, "\n";
+
+Under L<Perl6::Contexts>, you'll often need to write code equivalent to the follow:
+
+L<Perl6::Contexts> の影響下では以下と等価なコードを書く必要があります:
+
+  use Perl6::Contexts;
+  use autobox;
+  use autobox::Core;
+
+  my @arr = ( 1 .. 10 );
+  do_something(@arr->flatten);
+
+Array references can be iterated on using C<for> and C<foreach>. Both take a code
+reference as the body of the for statement. 
+C<foreach> passes the current element itself in each pass.
+C<for> passes the index of the current element in to that code block, and then
+the current element, and then a reference to the array itself.
+
+配列リファレンスは C<for> 及び C<foreach> を使ってイテレーションする
+事も出来ます. どちらも for 文の本体としてコードリファレンスを
+取ります. C<foreach> は各取り渡しの中で現在のエレメント自身を
+渡します. C<for> はコードブロックに現在の要素のインデックス, そして現在の
+要素, さらに配列自身のリファレンスを渡します.
+
+  my $arr = [ 1 .. 10 ];
+  $arr->foreach(sub { print $_[0], "\n" });
+  $arr->for(sub { die unless $_[1] == $_[2]->[$_[0]] });
+
+C<sum> is a toy poke at doing L<Language::Functional>-like stuff:
+
+C<sum> は L<Language::Functional> っぽいことをするおもちゃぽっけです:
+
+  print $arrref->sum(), "\n";
+
+If this goes over well, I'll make L<Langauge::Functional> a dependency and expose
+its function as methods on the correct data types. Or maybe I will do this anyway.
+
+これがうまくいくことを吟味した上で, L<Langauge::Functional> に依存して
+その関数を適切なデータに対するメソッドとして露出させようと思います. 
+若しくはとりあえずで行うかもしれません.
+
+C<each> is like C<foreach> but for hash references. For each key in the hash,
+the code reference is invoked with the key and the corresponding value as arguments:
+
+C<each> は C<foreach> と似ていますがハッシュリファレンスに対して
+行います. ハッシュの中の各キーに対して, 引数にキーと対応する値を
+つけてコードリファレンスを呼び出します:
+
+  my $hashref = { foo => 10, bar => 20, baz => 30, quux => 40 };
+  $hashref->each(sub { print $_[0], ' is ', $_[1], "\n" });
+
+There is currently no way to have the elements sorted before they are handed to the
+code block. If someone requests a way of passing in a sort criteria, I'll implement it.
+
+今のところコードブロックに渡す前に要素をソートする方法はありません. 
+もし誰かがソートの判断基準を渡す方法を求めたら実装するでしょう.
+
+C<m> is C<< m// >> and C<s> is C<< s/// >>. These work on scalars.
+Pass a regular expression created with C<< qr// >> and specify flags to the regular expression
+as part of the regular expression using the C<< (?imsx-imsx) >> syntax documented in L<perlre>.
+C<m> returns an array reference so that things such as C<map> and C<grep> may be called on the result.
+
+C<m> は C<< m// >> で C<s> は C<< s/// >> です. これらはスカラー
+に対して動作します. C<< qr// >> で作成した正規表現と, L<perlre> 
+で記述されている C<< (?imsx-imsx) >> 構文を使った正規表現の一部
+として正規表現へのフラグを指定します. C<m> は配列リファレンスを
+返すので, C<map> や C<grep> といった物をその結果に対して呼び出す
+事も出来ます.
+
+  my ($street_number, $street_name, $apartment_number) =
+      "1234 Robin Drive #101"->m(qr{(\d+) (.*)(?: #(\d+))?})->elements;
+
+  print "$street_number $street_name $apartment_number\n";
+
+C<split> is called on a non-reference scalar with the regular expression passed in. This is
+done for consistency with C<m> and C<s>.
+
+C<split> はリファレンスではないスカラーに対して正規表現を伴って
+呼び出します. これは C<m> 及び C<s> と同じです.
+
+  print "10, 20, 30, 40"->split(qr{, ?})->elements, "\n";
+
+You may C<curry> code references:
+
+コードリファレンスを C<curry> 化することも出来ます.
+
+  $adding_up_numbers = sub {
+      my $first_number = shift;
+      my $second_number = shift;
+      return $first_number + $second_number;
+  };
+
+  my $adding_five_to_numbers = $adding_up_numbers->curry(5);
+
+  $adding_five_to_numbers->(20)->print; "\n"->print;
+
+That's it.
+
+以上.
+
+=head2 足りない部分
+
+Operators. I'm tired. I'll do it in the morning. Maybe. Send me a patch.
+
+演算子. でももう疲れたよ. それは朝にやるよ. 多分. パッチおくっといて.
+
+File and socket operations are already implemented in an object-oriented fashion
+care of L<IO::Handle> and L<IO::Socket::INET>.
+Functions listed in the L<perlfunc> headings "System V interprocess communication functions",
+"Fetching user and group info",
+"Fetching network info",
+"Keywords related to perl modules",
+"Functions for processes and process groups",
+"Keywords related to scoping",
+"Time-related functions",
+"Keywords related to the control flow of your perl program",
+"Functions for filehandles, files, or directories",
+and 
+"Input and output functions".
+These things are likely implemented in an object oriented fashion by other CPAN
+modules, are keywords and not functions,
+take no arguments,
+or don't make sense as part of the string, number, array, hash, or code API.
+C<srand> because you probably shouldn't be using it. 
+C<each> on hashes. There is no good reason it is missing.
+
+ファイルとソケットの操作は L<IO::Handle> と L<IO::Socket::INET> 
+の方でオブジェクト指向的に実装されています.
+L<perlfunc> の以下の見出しでリストアップされている物:
+"System V プロセス間通信関数(System V interprocess communication functions)", 
+"ユーザ及びグループ情報の取得(Fetching user and group info)", 
+"ネットワーク情報の取得(Fetching network info)", 
+"perl モジュールに関連するキーワード(Keywords related to perl modules)", 
+"プロセスとプロセスグループに対する関数(Functions for processes and process groups)", 
+"スコープに対する関数(Keywords related to scoping)", 
+"時間関係の関数(Time-related functions)",
+"perl プログラムのフロー制御に関するキーワード(Keywords related to
+the control flow of your perl program)", 
+"ファイルハンドル, ファイル, 若しくはディレクトリに対する関数(Functions
+for filehandles, files, or directories)", 
+そして "入出力関数(Input and output functions)".
+これらは他のCPANモジュールによってオブジェクト指向に実装されてそう
+なもの, 関数ではなくキーワード, 引数を取らない物, それか
+文字列, 数値, 配列, ハッシュ, コードのAPIとして意味がないもの
+たちです. 
+C<srand> は使うべきではないでしょう. 
+C<each> はハッシュに対して. それがないことの上手な理由はありません.
+
+=head2 autobox化
+
+I<This section quotes four pages from the manuscript of Perl 6 Now: The Core Ideas Illustrated with Perl 5 by myself, Scott Walters. The text appears in the book starting at page 248. This copy lacks the benefit of copyedit - the finished product is of higher quality. See the shameless plug in the SEE ALSO section for information on ordering Perl 6 Now.>
+
+I<このセクションでは私, Scott Walters による Perl 6 Now: The Core Ideas Illustrated with Perl 5 から4ページを引用しています. テキストは本の248ページ
+からあります. このコピーは複製の利益を欠いています - 完成した製品は
+より高品質です. Perl 6 Now のオーダーに関しては SEE ALSO セクションの
+無恥な広告を参照してください. >
+
+A I<box> is an object that contains a primitive variable.
+Boxes are used to endow primitive types with the capabilities of objects.
+This is essential in strongly typed languages but never strictly required in Perl.
+Programmers might write something like C<< my $number = Int->new(5) >>.
+This is manual boxing.
+To I<autobox> is to convert a simple type into an object type automatically, or only conceptually.
+This is done by the language.
+It makes a language look to programmers as if everything is an object while the interpreter
+is free to implement data storage however it pleases.
+Autoboxing is really making simple types such as numbers, strings, and arrays appear to be objects.
+
+I<box> とはプリミティブ変数を含んでいるオブジェクトです. box には
+プリミティブ型に対してオブジェクトとしての機能を賦与する為に
+使われます. これは強く型付けされた言語での要素であって厳密には
+Perl には必要のない物です. プログラマは C<< my $number = Int->new(5) >>
+と書くこともできます. これは手作業のbox化です. I<autobox> (自動box化)
+とは簡単な型をオブジェクト型に自動的に変換すること若しくはその
+概念です. これは言語によって行われます. これはプログラマに言語の
+インタプリタがデータ格納域の実装は自由であるにもかかわらず
+全てがオブジェクトであるかのように見せます. 
+autobox は実際に数値, 文字列, 配列といった簡単な型をオブジェクトとして
+具現化します.
+
+C<int>, C<num>, C<bit>, C<str>, and other types with lower case names, are primitives.
+They're fast to operate on, and require no more memory to store than the data held strictly requires.
+C<Int>, C<Num>, C<Bit>, C<Str>, and other types with an initial capital letter, are objects.
+These may be subclassed (inherited from) and accept traits, among other things.
+These objects are provided by the system for the sole purpose of representing primitive types as objects,
+though this has many ancillary benefits such as making C<is> and C<has> work.
+Perl provides C<Int> to encapsulate an C<int>, C<Num> to encapsulate a C<num>, C<Bit> to encapsulate a C<bit>, and so on.
+As Perl's implementations of hashes and dynamically expandable arrays store any type, not just objects, Perl
+programmers almost never are required to box primitive types in objects.
+Perl's power makes this feature less essential than it is in other languages.
+
+C<int>, C<num>, C<bit>, C<str>, そして他の小文字の名前の型は
+プリミティブです. これらは操作が速く, 格納の際にデータが厳密に必要と
+するより余計なメモリを必要としません. C<Int>, C<Num>, C<Bit>, C<Str>
+そして1文字目が大文字になっているその他の型はオブジェクトです. 
+これらはサブクラス化(他から派生)していて, 特徴その他を受け継いでいる
+でしょう. これらのオブジェクトはプリミティブ型をオブジェクトとして
+表現するというただ1つの目的のためにシステムによって提供されて
+いますが, これには C<is> や C<has> を機能させるといった多くの補助的な
+利益ももたらします. Perl は C<int> をくるむために C<Int> を, 
+C<num> をくるむために C<Num> を, C<bit> をくるむために C<Bit> を, 
+等々を提供します. Perl のハッシュや動的に拡張可能な配列の実装は
+オブジェクトだけでなく任意の型を格納できるため, Perl プログラマは
+プリミティブ型をオブジェクトにbox化する必要はほとんどありません. 
+Perl の力はこの機能を他の言語が行うより本質でなくしています.
+
+X<autobox>ing makes primitive objects and they're boxed versions equivalent.
+An C<int> may be used as an C<Int> with no constructor call, no passing, nothing.
+This applies to constants too, not just variables:
+
+X<autobox> autobox化はプリミティブをオブジェクトとし, それはbox化した
+ものと等価です. C<int> はコンストラクタを呼び出したり渡したりを全く
+することなしに C<Int> として使うことができます.
+
+  # Perl 6 - autoboxing associates classes with primitives types:
+  # Perl 6 - autobox 化はクラスとプリミティブ型を結びつけます. 
+
+  print 4.sqrt, "\n";
+
+This is perfectly valid Perl 6.
+
+これは完全に有効な Perl 6 の文です.
+
+All of this applies to hashes and arrays, as well:
+
+これはハッシュや配列にも同様に適用できます:
+
+  # Perl 6 - autoboxing associates classes with primitive types:
+  # Perl 6 - autobox 化はクラスとプリミティブ型を結びつけます. 
+
+  print [ 1 .. 20 ].elems, "\n";
+
+The language is free to implement data storage however it wishes but the programmer
+sees the variables as objects. 
+
+言語ではデータ格納域を好きなように実装できますが, プログラマからは
+変数がオブジェクトであるかのように見えます.
+
+Expressions using autoboxing read somewhat like Latin suffixes. 
+In the autoboxing mind-set, you might not say that something is "made more mnemonic",
+but has been "mnemonicified".
+
+autoboxを利用する式はラテン接尾辞のような何かのように読めます. 
+autoboxの精神では, 何かをより"mnemonic"にするというのではなくて, 
+それが "mnemonicified" されると言います.
+
+Autoboxing may be mixed with normal function calls. 
+In the case where the methods are available as functions and the functions are 
+available as methods, it is only a matter of personal taste how the expression should be written:
+
+autobox化は通常の関数呼び出しと混在できます. メソッドが関数として
+利用可能であり関数がメソッドとして利用可能である場合には, 式を
+どう記述するかは個人の嗜好に任せられています.
+
+  # Calling methods on numbers and strings, these three lines are equivalent
+  # Perl 6
+  # 数字と文字に対してメソッドの呼び出し, この3行は Perl 6 的に等価です.
+
+  print sqrt 4;
+  print 4.sqrt;
+  4.sqrt.print;
+
+The first of these three equivalents assumes that a global C<sqrt()> function exists. 
+This first example would fail to operate if this global function were removed and only
+a method in the C<Num> package was left.
+
+これら3つのうち最初の1つはグローバルな C<sqrt()> 関数が存在することを
+仮定しています. このグローバル関数が削除され C<Num> パッケージにのみ
+残った場合には最初の例は失敗します.
+
+Perl 5 had the beginnings of autoboxing with filehandles:
+
+Perl 5 ではファイルハンドルの autobox 化を始めました.
+
+  use IO::Handle;
+  open my $file, '<', 'file.txt' or die $!;
+  $file->read(my $data, -s $file);
+
+Here, C<read> is a method on a filehandle we opened but I<never blessed>. 
+This lets us say things like C<< $file->print(...) >> rather than the often ambagious
+C<< print $file ... >>. 
+To many people, much of the time, it makes more conceptual sense as well.
+
+ここで, C<read> は私たちが開いたファイルハンドル上のメソッドですが
+それはI<全く bless されていません>. これは曖昧な C<< print $file ... >>
+ではなく C<< $file->print(...) >> のようなものと言わせます. 
+多くの人々の多くの時間のために, これは同様により概念の意味を作ります.
+
+=head3 プリミティブ型をBox化する理由
+
+What good is all of this?
+
+これは結局何の役に立つの?
+
+=over 1
+
+=item Makes conceptual sense to programmers used to object interfaces as I<the> way
+to perform options. 
+
+オブジェクトインターフェースを使っているプログラマにオプションを処理
+するためのI<その>方法として概念的な感覚を生み出します.
+
+=item Alternative idiom. Doesn't require the programmer
+to write or read expressions with complex precedence rules or strange operators.
+
+もう一つの表現. プログラマに複雑な手続きルールや奇妙な演算子を
+読み書きさせる必要がありません.
+
+=item Many times that parenthesis would otherwise have to span a large expression, the expression
+may be rewritten such that the parenthesis span only a few primitive types.
+
+長大な式を補うための括弧が必要になる多くの状況では少しのプリミティブ型
+に括弧を補うだけに書き換えることができるでしょう.
+
+=item Code may often be written with fewer temporary variables.
+
+コードをより少ないテンポラリ変数で書き直すことができます.
+
+=item Autoboxing provides the benefits of boxed types without the memory bloat of 
+actually using objects to represent primitives. Autoboxing "fakes it".
+
+autobox はオブジェクトが実際にプリミティブ型を表現するために
+メモリをふくらませることなしに box された型の恩恵を提供します. 
+autobox は"それを擬装" します.
+
+=item Strings, numbers, arrays, hashes, and so on, each have their own API.
+Documentation for an C<exists> method for arrays doesn't have to explain how hashes are
+handled and vice versa.
+
+文字列, 数値, 配列, ハッシュ, その他はそれぞれ別々のAPIを持っています. 
+配列用の C<exists> メソッドのドキュメントではハッシュでそれが
+どのように処理されるかを説明する必要はありません.
+
+=item Perl tries to accommodate the notion that the "subject" of a statement 
+should be the first thing on the line, and autoboxing furthers this agenda.
+
+Perl は文の"主語"は行の先頭に置くべきであるという提案を試みていて, 
+そして autobox はこれを促進しています.
+
+=back
+
+Perl is an idiomatic language and this is an important idiom.
+
+Perl は慣用句的な言語であり, これは重要な表現です.
+
+=head3 主語を先頭に: 余談
+
+Perl's design philosophy promotes the idea that the language should be flexible enough
+to allow programmers to place the X<subject> of a statement first. 
+For example, C<< die $! unless read $file, 60 >> looks like the primary purpose of the statement is
+to C<die>. 
+While that might be the programmers primary goal, when it isn't, the programmer
+can communicate his real primary intention to programmers by reversing the order of 
+clauses while keeping the exact same logic: C<< read $file, 60 or die $! >>.
+Autoboxing is another way of putting the subject first. 
+Nouns make good subjects, and in programming, variables, constants, and object names are the nouns.
+Function and method names are verbs. 
+C<< $noun->verb() >> focuses the readers attention on the thing being acted on rather than the action being performed. 
+Compare to C<< $verb($noun) >>.
+
+Perl の設計哲学では, 言語はプログラマに文の先頭にX<主語>主語を置く
+のを許せるくらい十分に柔軟であるべきとあります. 例えば,
+C<< die $! unless read $file, 60 >> はこの文の第一の目的が C<die> で
+あるように見えます. それがプログラマの第一の目的と思いますが, 
+そうでないときにはプログラマは彼の第一の目的を全く同じロジックを
+保ったまま節の順序を反転させることで意思の疎通をとることができます:
+C<< read $file, 60 or die $! >>.autobox は主語を先頭に置く
+もう一つの方法です. 関数やメソッドは同士です. 
+C<< $noun->verb() >> は動作が処理されることではなく
+動作の対象となるそのものに読み手の注意を引くでしょう. 
+C<< $verb($noun) >> と比較してみてください.
+
+=head3 autobox化とメソッドの結果
+
+In Chapter 11 [Subroutines], we had examples of ways an expression could be
+written. 
+Here it is again:
+
+第11節 [サブルーチン] で, 式を記述する方法を例示しました. 
+ここでまた示します:
+
+  # Various ways to do the same thing:
+  # 同じことをするために様々な方法があります:
+
+  print(reverse(sort(keys(%hash))));          # Perl 5 - pathological parenthetic
+                                              # Perl 5 - 病的な括弧
+  print reverse sort keys %hash;              # Perl 5 - no unneeded parenthesis
+                                              # Perl 5 - 不要な括弧を削除
+
+  print(reverse(sort(%hash,keys))));          # Perl 6 - pathological
+                                              # Perl 6 - ç—…çš„
+  print reverse sort %hash.keys;              # Perl 6 - no unneeded parenthesis
+                                              # Perl 6 - 不要な括弧を除去
+
+  %hash.keys ==> sort ==> reverse ==> print;  # Perl 6 - pipeline operator
+                                              # Perl 6 - パイプライン演算子
+
+  %hash.keys.sort.reverse.print;              # Perl 6 - autobox
+
+  %hash->keys->sort->reverse->print;          # Perl 5 - autobox
+
+This section deals with the last two of these equivalents.
+These are method calls 
+
+この節ではこれら等価な式の中で最後の2つを扱います. 
+次のようなメソッド呼び出しを考えてみます:
+
+  use autobox;
+  use autobox::Core;
+  use Perl6::Contexts;
+
+  my %hash = (foo => 'bar', baz => 'quux');
+
+  %hash->keys->sort->reverse->print;          # Perl 5 - autobox
+
+  # prints "foo baz"
+
+Each method call returns an array reference, in this example.
+Another method call is immediately performed on this value.
+This feeding of the next method call with the result of the previous call is the common mode
+of use of autoboxing.
+Providing no other arguments to the method calls, however, is not common.
+
+この例においては, 各メソッド呼び出しは配列リファレンスを返します. 
+他のメソッド呼び出しはその値を直ぐに処理しています. 
+前の呼び出しの結果で次のメソッド呼び出しをするこの間隔は
+autobox の利用における一般的な用法です. メソッド呼び出しに何の
+引数も与えていないのは一般的というわけではありませんが.
+
+F<Perl6::Contexts> recognizes object context as provided by C<< -> >> and
+coerces C<%hash> into a reference, suitable for use with F<autobox>.
+F<autobox> associates primitive types, such as references of various sorts, with classes.
+F<autobox::Core> throws into those classes methods wrapping Perl's built-in functions.
+In the interest of full disclosure, F<Perl6::Contexts> and F<autobox::Core> are my creations.
+
+F<Perl6::Contexts> はオブジェクトのコンテキストが C<< -> >> によって
+定まることを認識して, C<%hash> をF<autobox> を利用するのに適切な
+リファレンスへと変換します. F<autobox> は様々な種類のリファレンスの
+ようなプリミティブ型を, クラスに関係させます. F<autobox::Core> は
+Perl の組み込み関数をラップしているそれらのクラスのメソッドに
+投げます. 全容を開示した背景に, F<Perl6::Contexts> と F<autobox::Core> 
+は私の制作ということもあります.
+
+=head3 式を簡単にするための autobox
+
+One of my pet peeves in programming is parenthesis that span large expression.
+It seems like about the time I'm getting ready to close the parenthesis I opened
+on the other side of the line, I realize that I've forgotten something, and I have to
+arrow back over or grab the mouse.
+When the expression is too long to fit on a single line, it gets broken up, then
+I must decide how to indent it if it grows to 3 or more lines.
+
+プログラミングにおいて私のお得意のいらいらの一つに, 
+長くなった式を補うための括弧があります. 
+それは行の始めで開いた括弧を閉じる準備をする時間のような物で, 
+忘れていた何かを思い出し, 矢印で戻るかマウスを捕まえなければなりません. 
+式が1行に納めるのには長すぎてしまったときには, それは分解され, 
+3行とかそれ以上であればどんな風にインデントするかも決めなければ
+なりません.
+
+  # Perl 5 - a somewhat complex expression
+  # Perl 5 - 何か複雑な式
+
+  print join("\n", map { CGI::param($_) } @cgi_vars), "\n";
+  # Perl 5 - again, using autobox:
+  # Perl 5 - もう一度, 今度は autobox で:
+
+  @cgi_vars->map(sub { CGI::param($_[0]) })->join("\n")->concat("\n")->print;
+
+The autoboxed version isn't shorter, but it reads from left to right, and
+the parenthesis from the C<join()> don't span nearly as many characters.
+The complex expression serving as the value being C<join()>ed in the non-autoboxed version 
+becomes, in the autoboxed version, a value to call the C<join()> method on.
+
+autobox を利用したバージョンは短いわけではありませんが, それは
+左から右に読むことが出来, C<join()> の括弧はたいした量の文字を囲む
+こともありません. autobox を使わないバージョンにある C<join()> 
+される値を提供している複雑な式は, autobox を利用するバージョン
+では, C<join()> メソッドを呼びだす元の値になっています.
+
+This C<print> statement takes a list of CGI parameter names, reads the values for
+each parameter, joins them together with newlines, and prints them with a newline
+after the last one.
+
+この C<print> 文は CGI パラメータ名のリストを取り, 各パラメータの
+値を読み, それらを改行でつなぎ合わせ, そして最後に改行をつけて
+出力しています.
+
+Pretending that this expression were much larger and it had to be broken to span
+several lines, or pretending that comments are to be placed after each part of 
+the expression, you might reformat it as such:
+
+敢えてこの式がより長く複数行に分ける必要があるとしたら, 
+それか各式要素にコメントをおくとしたら, それは次のようになるでしょう:
+
+  @cgi_vars->map(sub { CGI::param($_[0]) })  # turn CGI arg names into values
+                                             # CGI 引数名を値に.
+           ->join("\n")                      # join with newlines
+                                             # 改行で連結.
+           ->concat("\n")                    # give it a trailing newline
+                                             # 末尾の改行を追加.
+           ->print;                          # print them all out
+                                             # それら全部を出力.
+
+This could also have been written:
+
+若しくはこのようにも書けるでしょう:
+
+  sub { CGI::param($_[0]) }->map(@cgi_vars)  # turn CGI arg names into values
+                                             # CGI 引数名を値に.
+           ->join("\n")                      # join with newlines
+                                             # 改行で連結.
+           ->concat("\n")                    # give it a trailing newline
+                                             # 末尾の改行を追加.
+           ->print;                          # print them all out
+                                             # それら全部を出力.
+
+C<map()> is X<polymorphic>. 
+The C<map()> method defined in the C<CODE> package takes for its arguments the things
+to map.
+The C<map()> method defined in the C<ARRAY> package takes for its argument a code reference
+to apply to each element of the array.
+
+C<map()> は X<多態>多態性を持っています. C<CODE> パッケージで
+定義されている C<map()> メソッドは引数に map する対象物をとります. 
+C<ARRAY> パッケージに定義されている C<map()> は配列の各要素に
+適用させるコードリファレンスをその引数によります.
+
+I<Here ends the text quoted from the Perl 6 Now manuscript.>
+
+I<Perl 6 now の原稿からの引用はここまでです.>
+
+=head1 バグ
+
+Yes. Report them to the author, L<scott****@slowa*****>.
+This code is not well tested. 
+The API is not yet stable - Perl 6-ish things and local extensions are still being renamed.
+
+はい. それは作者, L<scott****@slowa*****> に送って下さい. 
+このコードはそんなにテストされていません. 
+API もまだ確定していません - Perl 6 的な物やローカルな拡張は
+今後もリネームされるかもしれません.
+
+=head1 履歴
+
+Version 0.3 fixes a problem where C<unpack> wasn't sure it had enough arguments
+according to a test introduced in Perl 5.8.6 or perhaps 5.8.5.
+This problem was reported by Ron Reidy - thanks Ron!
+Version 0.3 also added the references to Perl 6 Now and the excerpt.
+
+Version 0.3 では C<unpack> が Perl 5.8.6 かおそらく 5.8.5 で
+導入されたテストのために十分な引数を伴っていない問題を修正しました. 
+この現象は Ron Reidy から報告されました - ありがとう Ron!
+Version 0.3 では Perl 6 Now と抜粋へのリファレンスを追加
+しました.
+
+Version 0.2 rounded out the API and introduced the beginnings of functional-ish methods.
+
+Version 0.2 では API を完成させ, 関数的なメソッドを始めてみました.
+
+Version 0.1 was woefully incomplete.
+
+Version 0.1 は悲しいくらい不完全でした.
+
+=head1 関連項目
+
+L<autobox>. 
+
+
+L<Perl6::Contexts>.
+
+
+Perl 6: L<< http://dev.perl.org/perl6/apocalypse/ >>.
+
+
+(Shameless plug alert!) I<Perl 6 Now: The Core Ideas Illustrated with Perl 5>
+dedicates a sizable portion of Chapter 14, Objects, to autoboxing
+and the idea is used heavily throughout the book. Chapter 8, Data Structures,
+also has numerous examples. 
+See L<http://perl6now.com> or look for ISBN 1-59059-395-2 at your favorite
+bookstore for more information.
+
+(広告警告!) I<Perl 6 Now: The Core Ideas Illustrated with Perl 5> 
+はその第14節, オブジェクトのかなりの部分を, autoboxにさいていて, 
+またその発想は全体を通して強く使われています. 第8節, データ構造
+にも多数の例があります. 
+詳しい情報は  L<http://perl6now.com> か, お気に入りの書店で
+ISBN 1-59059-395-2 を確認してみて下さい.
+
+=head1 著者
+
+Scott Walters, L<scott****@slowa*****>
+Thanks to chocolateboy for L<autobox> and for the encouragement!
+
+Scott Walters, L<scott****@slowa*****>
+chocolateboy, L<autobox> を, そして激励をありがとう!
+
+=begin COMMENT
+
+和訳
+
+ 山科 氷魚 (YAMASHINA Hio) <hio****@hio*****>
+
+Origlnal distribution is autobox-Core VERSION 0.3.
+Translated at 2006-10-26.
+
+原典: autobox-Core VERSION 0.3.
+翻訳日: 2006-10-26.
+
+=end COMMENT
+


perldocjp-cvs メーリングリストの案内
Back to archive index