Date: Tuesday January 05, 2021 @ 02:02 Author: argrath Update of /cvsroot/perldocjp/docs/perl/5.16.1 In directory sf-cvs:/tmp/cvs-serv71174/perl/5.16.1 Added Files: perlobj.pod Log Message: 5.16.1/perlobj =================================================================== File: perlobj.pod Status: Up-to-date Working revision: 1.1 Mon Jan 4 17:02:14 2021 Repository revision: 1.1 /cvsroot/perldocjp/docs/perl/5.16.1/perlobj.pod,v Sticky Options: -kb Existing Tags: No Tags Exist -------------- next part -------------- Index: docs/perl/5.16.1/perlobj.pod diff -u /dev/null docs/perl/5.16.1/perlobj.pod:1.1 --- /dev/null Tue Jan 5 02:02:15 2021 +++ docs/perl/5.16.1/perlobj.pod Tue Jan 5 02:02:14 2021 @@ -0,0 +1,2350 @@ + +=encoding euc-jp + +=for comment +Consistent formatting of this file is achieved with: + perl ./Porting/podtidy pod/perlobj.pod + +=head1 NAME +X<object> X<OOP> + +=begin original + +perlobj - Perl object reference + +=end original + +perlobj - Perl ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥ê¥Õ¥¡¥ì¥ó¥¹ + +=head1 DESCRIPTION + +=begin original + +This document provides a reference for Perl's object orientation +features. If you're looking for an introduction to object-oriented +programming in Perl, please see L<perlootut>. + +=end original + +¤³¤Îʸ½ñ¤Ï¡¢Perl ¤Î¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þµ¡Ç½¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤òÄ󶡤·¤Þ¤¹¡£ +Perl ¤Ç¤Î¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ¥×¥í¥°¥é¥ß¥ó¥°¤Î³µÍפòõ¤·¤Æ¤¤¤ë¤Ê¤é¡¢ +L<perlootut> ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=begin original + +In order to understand Perl objects, you first need to understand +references in Perl. See L<perlref> for details. + +=end original + +Perl ¤Î¥ª¥Ö¥¸¥§¥¯¥È¤òÍý²ò¤¹¤ë¤¿¤á¤Ë¤Ï¡¢¤Þ¤º Perl ¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò +Íý²ò¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£ +¾Ü¤·¤¯¤Ï L<perlref> ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=begin original + +This document describes all of Perl's object-oriented (OO) features +from the ground up. If you're just looking to write some +object-oriented code of your own, you are probably better served by +using one of the object systems from CPAN described in L<perlootut>. + +=end original + +¤³¤Îʸ½ñ¤Ï Perl ¤Î¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ (OO) µ¡Ç½¤ÎÁ´¤Æ¤ò°ì¤«¤éµ½Ò¤·¤Æ¤¤¤Þ¤¹¡£ +ñ¤Ë¼«Ê¬¼«¿È¤Ç¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ¤Î¥³¡¼¥É¤ò½ñ¤¯ÊýË¡¤òõ¤·¤Æ¤¤¤ë¤Ê¤é¡¢ +¤ª¤½¤é¤¯ CPAN ¤«¤é L<perlootut> ¤Ëµ½Ò¤µ¤ì¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¥·¥¹¥Æ¥à¤Î +°ì¤Ä¤ò»È¤¦¤³¤È¤Ë¤è¤Ã¤Æ¤è¤ê¤è¤¯°·¤¨¤ë¤Ç¤·¤ç¤¦¡£ + +=begin original + +If you're looking to write your own object system, or you need to +maintain code which implements objects from scratch then this document +will help you understand exactly how Perl does object orientation. + +=end original + +¼«Ê¬¼«¿È¤Î¥ª¥Ö¥¸¥§¥¯¥È¥·¥¹¥Æ¥à¤Î½ñ¤Êý¤òõ¤·¤Æ¤¤¤¿¤ê¡¢ +°ì¤«¤é¥ª¥Ö¥¸¥§¥¯¥È¤ò¼ÂÁõ¤·¤Æ¤¤¤ë¥³¡¼¥É¤òÊá¼ê¤¹¤ëɬÍפ¬¤¢¤ë¤Ê¤é¡¢ +¤³¤Îʸ½ñ¤Ï¤É¤¦¤ä¤Ã¤Æ Perl ¤¬¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ¤ò¹Ô¤Ã¤Æ¤¤¤ë¤«¤òÀµ³Î¤Ë +Íý²ò¤¹¤ë½õ¤±¤Ë¤Ê¤ë¤Ç¤·¤ç¤¦¡£ + +=begin original + +There are a few basic principles which define object oriented Perl: + +=end original + +¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ Perl ¤òÄêµÁ¤¹¤ë¤¤¤¯¤Ä¤«¤Î´ðËÜŪ¤Ê¸¶Â§¤¬¤¢¤ê¤Þ¤¹: + +=over 4 + +=item 1. + +=begin original + +An object is simply a data structure that knows to which class it +belongs. + +=end original + +¥ª¥Ö¥¸¥§¥¯¥È¤Ïñ¤Ë¡¢¤É¤Î¥¯¥é¥¹¤Ë°¤¹¤ë¤«¤òÃΤäƤ¤¤ë¥Ç¡¼¥¿¹½Â¤¤Ç¤¹¡£ + +=item 2. + +=begin original + +A class is simply a package. A class provides methods that expect to +operate on objects. + +=end original + +¥¯¥é¥¹¤Ïñ¤Ë¥Ñ¥Ã¥±¡¼¥¸¤Ç¤¹¡£ +¥¯¥é¥¹¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤òÁàºî¤¹¤ë¤³¤È¤òÁÛÄꤷ¤¿¥á¥½¥Ã¥É¤òÄ󶡤·¤Þ¤¹¡£ + +=item 3. + +=begin original + +A method is simply a subroutine that expects a reference to an object +(or a package name, for class methods) as the first argument. + +=end original + +¥á¥½¥Ã¥É¤Ïñ¤Ë¡¢ºÇ½é¤Î°ú¿ô¤È¤·¤Æ¥ª¥Ö¥¸¥§¥¯¥È (¤Þ¤¿¤Ï¥¯¥é¥¹¥á¥½¥Ã¥É¤Î¾ì¹ç¤Ï +¥Ñ¥Ã¥±¡¼¥¸Ì¾) ¤òÁÛÄꤹ¤ë¥µ¥Ö¥ë¡¼¥Á¥ó¤Ç¤¹¡£ + +=back + +=begin original + +Let's look at each of these principles in depth. + +=end original + +¤½¤ì¤¾¤ì¤Î¸¶Â§¤ò¿¼¤¯¸«¤Æ¤ß¤Þ¤·¤ç¤¦¡£ + +=head2 An Object is Simply a Data Structure +X<object> X<bless> X<constructor> X<new> + +(¥ª¥Ö¥¸¥§¥¯¥È¤Ïñ¤Ê¤ë¥Ç¡¼¥¿¹½Â¤) + +=begin original + +Unlike many other languages which support object orientation, Perl does +not provide any special syntax for constructing an object. Objects are +merely Perl data structures (hashes, arrays, scalars, filehandles, +etc.) that have been explicitly associated with a particular class. + +=end original + +¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ¤ËÂбþ¤·¤Æ¤¤¤ë¤½¤Î¾¤Î¿¤¯¤Î¸À¸ì¤È°ã¤Ã¤Æ¡¢ +Perl ¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤ò¹½ÃÛ¤¹¤ë¤¿¤á¤ÎÆÃÊ̤Êʸˡ¤òÄ󶡤·¤Æ¤¤¤Þ¤»¤ó¡£ +¥ª¥Ö¥¸¥§¥¯¥È¤Ï¡¢ÆÃÄê¤Î¥¯¥é¥¹¤ÈÌÀ¼¨Åª¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤Æ¤¤¤ë +ñ¤Ê¤ë Perl ¥Ç¡¼¥¿¹½Â¤(¥Ï¥Ã¥·¥å¡¢ÇÛÎó¡¢¥¹¥«¥é¡¢¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ê¤É)¤Ç¤¹¡£ + +=begin original + +That explicit association is created by the built-in C<bless> function, +which is typically used within the I<constructor> subroutine of the +class. + +=end original + +ÌÀ¼¨Åª¤Ê´ØÏ¢ÉÕ¤±¤ÏÁȤ߹þ¤ß¤Î C<bless> ´Ø¿ô¤Ë¤è¤Ã¤Æºî¤é¤ì¤Þ¤¹; +¤³¤ì¤Ïŵ·¿Åª¤Ë¤Ï¥¯¥é¥¹¤Î I<¥³¥ó¥¹¥È¥é¥¯¥¿> ¥µ¥Ö¥ë¡¼¥Á¥ó¤ÎÃæ¤Ç»È¤ï¤ì¤Þ¤¹¡£ + +=begin original + +Here is a simple constructor: + +=end original + +°Ê²¼¤Ïñ½ã¤Ê¥³¥ó¥¹¥È¥é¥¯¥¿¤Ç¤¹: + + package File; + + sub new { + my $class = shift; + + return bless {}, $class; + } + +=begin original + +The name C<new> isn't special. We could name our constructor something +else: + +=end original + +C<new> ¤È¤¤¤¦Ì¾Á°¤ÏÆÃÊ̤ǤϤ¢¤ê¤Þ¤»¤ó¡£ +¥³¥ó¥¹¥È¥é¥¯¥¿¤Ë¾¤Î̾Á°¤òÉÕ¤±¤ë¤³¤È¤â½ÐÍè¤Þ¤¹: + + package File; + + sub load { + my $class = shift; + + return bless {}, $class; + } + +=begin original + +The modern convention for OO modules is to always use C<new> as the +name for the constructor, but there is no requirement to do so. Any +subroutine that blesses a data structure into a class is a valid +constructor in Perl. + +=end original + +OO ¥â¥¸¥å¡¼¥ë¤Î¥â¥À¥ó¤Ê´·½¬¤Ï¡¢¥³¥ó¥¹¥È¥é¥¯¥¿¤Î̾Á°¤È¤·¤Æ +¾ï¤Ë C<new> ¤ò»È¤¦¤È¤¤¤¦¤â¤Î¤Ç¤¹¤¬¡¢¤½¤¦¤¹¤ëɬÍ×À¤Ï¤¢¤ê¤Þ¤»¤ó¡£ +¥Ç¡¼¥¿¹½Â¤¤ò¥¯¥é¥¹¤Ë bless ¤¹¤ë¤É¤ó¤Ê¥µ¥Ö¥ë¡¼¥Á¥ó¤â Perl ¤Ç¤Î +ÀµÅö¤Ê¥³¥ó¥¹¥È¥é¥¯¥¿¤Ç¤¹¡£ + +=begin original + +In the previous examples, the C<{}> code creates a reference to an +empty anonymous hash. The C<bless> function then takes that reference +and associates the hash with the class in C<$class>. In the simplest +case, the C<$class> variable will end up containing the string "File". + +=end original + +Á°½Ò¤ÎÎã¤Ç¡¢C<{}> ¤È¤¤¤¦¥³¡¼¥É¤Ï¡¢¶õ¤Î̵̾¥Ï¥Ã¥·¥å¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò +ºî¤ê¤Þ¤¹¡£ +¤½¤ì¤«¤é C<bless> ÊÑ¿ô¤Ï¤³¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò¼è¤ê¡¢¥Ï¥Ã¥·¥å¤ò +C<$class> ¤Î¥¯¥é¥¹¤È´ØÏ¢ÉÕ¤±¤Þ¤¹¡£ +ºÇ¤âñ½ã¤Ê¾ì¹ç¤Ç¤Ï¡¢C<$class> ÊÑ¿ô¤Ï "File" ¤È¤¤¤¦Ê¸»úÎó¤ò´Þ¤ó¤Ç¤¤¤Þ¤¹¡£ + +=begin original + +We can also use a variable to store a reference to the data structure +that is being blessed as our object: + +=end original + +¤Þ¤¿¡¢¥ª¥Ö¥¸¥§¥¯¥È¤È¤·¤Æ bless ¤¹¤ë¥Ç¡¼¥¿¹½Â¤¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤òÊä´°¤¹¤ë +ÊÑ¿ô¤ò»È¤¦¤³¤È¤â½ÐÍè¤Þ¤¹: + + sub new { + my $class = shift; + + my $self = {}; + bless $self, $class; + + return $self; + } + +=begin original + +Once we've blessed the hash referred to by C<$self> we can start +calling methods on it. This is useful if you want to put object +initialization in its own separate method: + +=end original + +C<$self> ¤Ç»²¾È¤µ¤ì¤Æ¤¤¤ë¥Ï¥Ã¥·¥å¤ò bless ¤¹¤ì¤Ð¡¢ +¤½¤ì¤Ë´Þ¤Þ¤ì¤ë¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤·»Ï¤á¤é¤ì¤Þ¤¹¡£ +¥ª¥Ö¥¸¥§¥¯¥È¤Î½é´ü²½¤òÆȼ«¤ÎʬΥ¤µ¤ì¤¿¥á¥½¥Ã¥É¤Ç¹Ô¤¤¤¿¤¤¾ì¹ç¤Ë +¤³¤ì¤ÏÍÍѤǤ¹: + + sub new { + my $class = shift; + + my $self = {}; + bless $self, $class; + + $self->_initialize(); + + return $self; + } + +=begin original + +Since the object is also a hash, you can treat it as one, using it to +store data associated with the object. Typically, code inside the class +can treat the hash as an accessible data structure, while code outside +the class should always treat the object as opaque. This is called +B<encapsulation>. Encapsulation means that the user of an object does +not have to know how it is implemented. The user simply calls +documented methods on the object. + +=end original + +¥ª¥Ö¥¸¥§¥¯¥È¤Ï¥Ï¥Ã¥·¥å¤Ç¤â¤¢¤ë¤Î¤Ç¡¢¤³¤ì¤ò¥Ï¥Ã¥·¥å¤È¤·¤Æ°·¤¦¤³¤È¤¬½ÐÍè¡¢ +¥ª¥Ö¥¸¥§¥¯¥È¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Ç¡¼¥¿¤òÊݴɤ¹¤ë¤Î¤Ë»È¤¨¤Þ¤¹¡£ +ŵ·¿Åª¤Ë¤Ï¡¢¥¯¥é¥¹Æâ¤Î¥³¡¼¥É¤Ï¥Ï¥Ã¥·¥å¤ò¥¢¥¯¥»¥¹²Äǽ¤Ê¥Ç¡¼¥¿¹½Â¤¤È¤·¤Æ +°·¤¤¡¢¥¯¥é¥¹¤Î³°Â¦¤Î¥³¡¼¥É¤Ï¾ï¤Ë¥ª¥Ö¥¸¥§¥¯¥È¤òÉÔÆ©ÌÀ¤Ê¤â¤Î¤È¤·¤Æ +°·¤¦¤Ù¤¤Ç¤¹¡£ +¤³¤ì¤Ï B<¥«¥×¥»¥ë²½> ¤È¸Æ¤Ð¤ì¤Þ¤¹¡£ +¥«¥×¥»¥ë²½¤È¤Ï¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Î¥æ¡¼¥¶¡¼¤Ï¤½¤ì¤¬¤É¤Î¤è¤¦¤Ë¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¤«¤ò +ÃΤëɬÍפ¬¤Ê¤¤¤È¤¤¤¦¤³¤È¤Ç¤¹¡£ +¥æ¡¼¥¶¡¼¤Ïñ¤Ë¥ª¥Ö¥¸¥§¥¯¥È¤Îʸ½ñ²½¤µ¤ì¤¿¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤·¤Þ¤¹¡£ + +=begin original + +Note, however, that (unlike most other OO languages) Perl does not +ensure or enforce encapsulation in any way. If you want objects to +actually I<be> opaque you need to arrange for that yourself. This can +be done in a varierty of ways, including using L<"Inside-Out objects"> +or modules from CPAN. + +=end original + +¤·¤«¤·¡¢(¤½¤Î¾¤Î OO ¸À¸ì¤Î¤Û¤È¤ó¤É¤È°ã¤Ã¤Æ) Perl ¤Ï¤Ê¤ó¤é¤«¤ÎÊýË¡¤Ç +¥«¥×¥»¥ë²½¤òÊݾڤ·¤¿¤ê¶¯À©¤·¤¿¤ê¤·¤Þ¤»¤ó¡£ +¤â¤·¤¢¤Ê¤¿¤¬¥ª¥Ö¥¸¥§¥¯¥È¤òËÜÅö¤ËÉÔÆ©ÌÀ¤Ë I<¤¹¤ë> ¤³¤È¤ò˾¤à¤Ê¤é¡¢ +¤¢¤Ê¤¿¼«¿È¤Ç¤½¤¦¤Ê¤ë¤è¤¦¤Ë½àÈ÷¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£ +¤³¤ì¤ò¤¹¤ë¤Ë¤Ï¡¢L<"Inside-Out objects"> ¤ä CPAN ¤Î¥â¥¸¥å¡¼¥ë¤ò»È¤¦¤³¤È¤ò +´Þ¤á¤ÆÍÍ¡¹¤ÊÊýË¡¤¬¤¢¤ê¤Þ¤¹¡£ + +=head3 Objects Are Blessed; Variables Are Not + +(¥ª¥Ö¥¸¥§¥¯¥È¤Ï bless ¤µ¤ì¤Æ¤¤¤ë; ÊÑ¿ô¤Ï¤µ¤ì¤Æ¤¤¤Ê¤¤) + +=begin original + +When we bless something, we are not blessing the variable which +contains a reference to that thing, nor are we blessing the reference +that the variable stores; we are blessing the thing that the variable +refers to (sometimes known as the I<referent>). This is best +demonstrated with this code: + +=end original + +»ä¤¿¤Á¤¬²¿¤«¤ò bless ¤¹¤ë¤È¤¡¢ +»ä¤¿¤Á¤Ï¤½¤Î¤â¤Î¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò´Þ¤ó¤Ç¤¤¤ëÊÑ¿ô¤ò bless ¤·¤Æ¤¤¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢ +ÊÑ¿ô¤ËÊݴɤµ¤ì¤Æ¤¤¤ë¥ê¥Õ¥¡¥ì¥ó¥¹¤ò bless ¤·¤Æ¤¤¤ë¤Î¤Ç¤â¤¢¤ê¤Þ¤»¤ó¡£ +»ä¤¿¤Á¤ÏÊÑ¿ô¤¬»²¾È¤·¤Æ¤¤¤ë²¿¤«(»þ¡¹ I<»²¾ÈÀè> (referent) ¤È¤·¤ÆÃΤé¤ì¤Þ¤¹) ¤ò +bless ¤·¤Æ¤¤¤Þ¤¹¡£ +¤³¤ì¤Ï¤³¤Î¥³¡¼¥É¤ÇºÇ¤âÎɤ¯É½¤µ¤ì¤Æ¤¤¤Þ¤¹: + + use Scalar::Util 'blessed'; + + my $foo = {}; + my $bar = $foo; + + bless $foo, 'Class'; + print blessed( $bar ); # prints "Class" + + $bar = "some other value"; + print blessed( $bar ); # prints undef + +=begin original + +When we call C<bless> on a variable, we are actually blessing the +underlying data structure that the variable refers to. We are not +blessing the reference itself, nor the variable that contains that +reference. That's why the second call to C<blessed( $bar )> returns +false. At that point C<$bar> is no longer storing a reference to an +object. + +=end original + +ÊÑ¿ô¤ËÂФ·¤Æ C<bless> ¤ò¸Æ¤Ó½Ð¤¹¤È¡¢¼ÂºÝ¤Ë¤ÏÊÑ¿ô¤¬»²¾È¤·¤Æ¤¤¤ë +´ð¤È¤Ê¤ë¥Ç¡¼¥¿¹½Â¤¤ò bless ¤·¤Æ¤¤¤Þ¤¹¡£ +¥ê¥Õ¥¡¥ì¥ó¥¹¼«¿È¤ä¡¢¥ê¥Õ¥¡¥ì¥ó¥¹¤òÊݴɤ·¤Æ¤¤¤ëÊÑ¿ô¤ò bless ¤·¤Æ¤¤¤ë¤Î¤Ç¤Ï +¤¢¤ê¤Þ¤»¤ó¡£ +¤³¤ì¤¬¡¢2 ÈÖÌܤΠC<blessed( $bar )> ¤¬µ¶¤òÊÖ¤¹Íýͳ¤Ç¤¹¡£ +¤³¤Î»þÅÀ¤Ç¤Ï C<$bar> ¤Ï¤â¤Ï¤ä¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò +Êݴɤ·¤Æ¤¤¤Þ¤»¤ó¡£ + +=begin original + +You will sometimes see older books or documentation mention "blessing a +reference" or describe an object as a "blessed reference", but this is +incorrect. It isn't the reference that is blessed as an object; it's +the thing the reference refers to (i.e. the referent). + +=end original + +»þ¡¹¸Å¤¤Ëܤäʸ½ñ¤Ç¡Ö¥ê¥Õ¥¡¥ì¥ó¥¹¤ò bless ¤¹¤ë¡×¤È¤¤¤¦µ½Ò¤ä¡¢ +¥ª¥Ö¥¸¥§¥¯¥È¤Î¤³¤È¤ò¡Öbless ¤µ¤ì¤¿¥ê¥Õ¥¡¥ì¥ó¥¹¡×¤ÈÀâÌÀ¤·¤Æ¤¤¤ë¤Î¤ò +¸«¤ë¤«¤âÃΤì¤Þ¤»¤ó¤¬¡¢¤³¤ì¤ÏÉÔÀµ³Î¤Ç¤¹¡£ +bless ¤µ¤ì¤¿¥ê¥Õ¥¡¥ì¥ó¥¹¤¬¥ª¥Ö¥¸¥§¥¯¥È¤Ê¤Î¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó; +¥ê¥Õ¥¡¥ì¥ó¥¹¤¬ºÇ¾®¤·¤Æ¤¤¤ë¤â¤Î (¤Ä¤Þ¤ê»²¾ÈÀè) ¤Ç¤¹¡£ + +=head2 A Class is Simply a Package +X<class> X<package> X<@ISA> X<inheritance> + +(¥¯¥é¥¹¤Ïñ¤Ê¤ë¥Ñ¥Ã¥±¡¼¥¸) + +=begin original + +Perl does not provide any special syntax for class definitions. A +package is simply a namespace containing variables and subroutines. The +only difference is that in a class, the subroutines may expect a +reference to an object or the name of a class as the first argument. +This is purely a matter of convention, so a class may contain both +methods and subroutines which I<don't> operate on an object or class. + +=end original + +Perl ¤Ï¥¯¥é¥¹ÄêµÁ¤Î¤¿¤á¤ÎÆÃÊ̤Êʸˡ¤òÄ󶡤·¤Þ¤»¤ó¡£ +¥Ñ¥Ã¥±¡¼¥¸¤ÏÊÑ¿ô¤È¥µ¥Ö¥ë¡¼¥Á¥ó¤ò´Þ¤àñ¤Ê¤ë̾Á°¶õ´Ö¤Ç¤¹¡£ +¥¯¥é¥¹¤È¤ÎÍ£°ì¤Î°ã¤¤¤Ï¡¢¥µ¥Ö¥ë¡¼¥Á¥ó¤Ï¤½¤ÎºÇ½é¤Î°ú¿ô¤Ë +¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤«¥¯¥é¥¹Ì¾¤òÁÛÄꤹ¤ë¤È¸À¤¦¤³¤È¤Ç¤¹¡£ +¤³¤ì¤Ï½ã¿è¤Ëµ¬Ìó¤ÎÌäÂê¤Ê¤Î¤Ç¡¢°ì¤Ä¤Î¥¯¥é¥¹¤Ë¥á¥½¥Ã¥É¤È¡¢¥ª¥Ö¥¸¥§¥¯¥È¤ä +¥¯¥é¥¹¤òÁàºî I<¤·¤Ê¤¤> ¥µ¥Ö¥ë¡¼¥Á¥ó¤ÎξÊý¤ò´Þ¤à¤³¤È¤â½ÐÍè¤Þ¤¹¡£ + +=begin original + +Each package contains a special array called C<@ISA>. The C<@ISA> array +contains a list of that class's parent classes, if any. This array is +examined when Perl does method resolution, which we will cover later. + +=end original + +³Æ¥Ñ¥Ã¥±¡¼¥¸¤Ï C<@ISA> ¤È¸Æ¤Ð¤ì¤ëÆÃÊ̤ÊÇÛÎó¤ò»ý¤Á¤Þ¤¹¡£ +C<@ISA> ÇÛÎó¤Ï (¤â¤·¤¢¤ì¤Ð) ¤½¤Î¥¯¥é¥¹¤Î¿Æ¥¯¥é¥¹¤Î°ìÍ÷¤«¤é¤Ê¤ê¤Þ¤¹¡£ +¤³¤ÎÇÛÎó¤Ï¡¢¸å½Ò¤¹¤ë¡¢Perl ¤¬¥á¥½¥Ã¥É²ò·è¤ò¤¹¤ë¤È¤¤Ë¥Á¥§¥Ã¥¯¤µ¤ì¤Þ¤¹¡£ + +=begin original + +It is possible to manually set C<@ISA>, and you may see this in older +Perl code. Much older code also uses the L<base> pragma. For new code, +we recommend that you use the L<parent> pragma to declare your parents. +This pragma will take care of setting C<@ISA>. It will also load the +parent classes and make sure that the package doesn't inherit from +itself. + +=end original + +¼êÆ°¤Ç C<@ISA> ¤Ï²Äǽ¤Ç¡¢¸Å¤¤ Perl ¥³¡¼¥É¤Ç¤Ï¤½¤ì¤ò¸«¤ë¤«¤âÃΤì¤Þ¤»¤ó¡£ +¤µ¤é¤Ë¸Å¤¤¥³¡¼¥É¤Ç¤Ï L<base> ¥×¥é¥°¥Þ¤â»È¤¤¤Þ¤¹¡£ +¿·¤·¤¤¥³¡¼¥É¤Ç¤Ï¡¢¿Æ¤òÀë¸À¤¹¤ë¤¿¤á¤Ë +we recommend that you use the +L<parent> ¥×¥é¥°¥Þ¤ò»È¤¦¤³¤È¤ò´«¤á¤Þ¤¹¡£ +¤³¤Î¥×¥é¥°¥Þ¤Ï C<@ISA> ¤ÎÀßÄê¤ÎÀ¤Ïäò¤·¤Þ¤¹¡£ +¤³¤ì¤Ï¤Þ¤¿¡¢¿Æ¥¯¥é¥¹¤òÆɤ߹þ¤ó¤Ç¡¢¥Ñ¥Ã¥±¡¼¥¸¤¬¤½¤ì¼«¿È¤«¤é +·Ñ¾µ¤µ¤ì¤Æ¤¤¤Ê¤¤¤³¤È¤ò³Îǧ¤·¤Þ¤¹¡£ + +=begin original + +However the parent classes are set, the package's C<@ISA> variable will +contain a list of those parents. This is simply a list of scalars, each +of which is a string that corresponds to a package name. + +=end original + +¤·¤«¤·¡¢¿Æ¥¯¥é¥¹¤¬ÀßÄꤵ¤ì¤ë¤È¡¢¤½¤Î¥Ñ¥Ã¥±¡¼¥¸¤Î C<@ISA> ÊÑ¿ô¤Ï +¤½¤ì¤é¤Î¿Æ¤Î¥ê¥¹¥È¤Ë¤Ê¤ê¤Þ¤¹¡£ +¤³¤ì¤Ïñ½ã¤Ë¥¹¥«¥é¤Î¥ê¥¹¥È¤Ç¡¢¤½¤ì¤¾¤ì¤Ï¥Ñ¥Ã¥±¡¼¥¸Ì¾¤ËÂбþ¤¹¤ë +ʸ»úÎó¤Ç¤¹¡£ + +=begin original + +All classes inherit from the L<UNIVERSAL> class implicitly. The +L<UNIVERSAL> class is implemented by the Perl core, and provides +several default methods, such as C<isa()>, C<can()>, and C<VERSION()>. +The C<UNIVERSAL> class will I<never> appear in a package's C<@ISA> +variable. + +=end original + +Á´¤Æ¤Î¥¯¥é¥¹¤Ï°ÅÌÛ¤Ë L<UNIVERSAL> ¤¯¤é¤¹¤«¤é¤±¤¤¤·¤ç¤¦¤µ¤ì¤Þ¤¹¡£ +L<UNIVERSAL> ¥¯¥é¥¹¤Ï Perl ¥³¥¢¤Ë¤è¤Ã¤Æ¼ÂÁõs¤ì¤Æ¤¤¤Æ¡¢ +C<isa()>, C<can()>, and C<VERSION()> ¤Î¤è¤¦¤Ê¤¤¤¯¤Ä¤«¤Î¥Ç¥Õ¥©¥ë¥È¥á¥½¥Ã¥É¤ò +Ä󶡤·¤Þ¤¹¡£ +C<UNIVERSAL> ¥¯¥é¥¹¤Ï I<·è¤·¤Æ> ¥Ñ¥Ã¥±¡¼¥¸¤Î C<@ISA> ÊÑ¿ô¤Ëɽ¤ì¤Þ¤»¤ó¡£ + +=begin original + +Perl I<only> provides method inheritance as a built-in feature. +Attribute inheritance is left up the class to implement. See the +L</Writing Accessors> section for details. + +=end original + +Perl ¤ÏÁȤ߹þ¤ßµ¡Ç½¤È¤·¤Æ¥á¥½¥Ã¥É·Ñ¾µ I<¤Î¤ß> ¤òÄ󶡤·¤Þ¤¹¡£ +°À·Ñ¾µ¤Ï¼ÂÁõ¤µ¤ì¤ë¥¯¥é¥¹¤Ë»Ä¤µ¤ì¤Æ¤¤¤Þ¤¹¡£ +¾Ü¤·¤¯¤Ï L</Writing Accessors> Àá¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=head2 A Method is Simply a Subroutine +X<method> + +(¥á¥½¥Ã¥É¤Ïñ¤Ê¤ë¥µ¥Ö¥ë¡¼¥Á¥ó) + +=begin original + +Perl does not provide any special syntax for defining a method. A +method is simply a regular subroutine, and is declared with C<sub>. +What makes a method special is that it expects to receive either an +object or a class name as its first argument. + +=end original + +Perl ¤Ï¥á¥½¥Ã¥É¤òÄêµÁ¤¹¤ë¤¿¤á¤ÎÆÃÊ̤Êʸˡ¤òÄ󶡤·¤Þ¤»¤ó¡£ +¥á¥½¥Ã¥É¤Ïñ¤ËÄ̾ï¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¤Ç¡¢C<sub> ¤Ë¤è¤Ã¤ÆÀë¸À¤µ¤ì¤Þ¤¹¡£ +¥á¥½¥Ã¥É¤òÆÃÊ̤ˤ·¤Æ¤¤¤ë¤Î¤Ï¡¢¤½¤ì¤¬ºÇ½é¤Î°ú¿ô¤È¤·¤Æ +¥ª¥Ö¥¸¥§¥¯¥È¤«¥¯¥é¥¹Ì¾¤ò¼õ¤±¼è¤ë¤³¤È¤òÁÛÄꤷ¤Æ¤¤¤ë¤È¸À¤¦¤³¤È¤Ç¤¹¡£ + +=begin original + +Perl I<does> provide special syntax for method invocation, the C<< -> +>> operator. We will cover this in more detail later. + +=end original + +Perl ¤Ë¤Ï C<< -> >> ±é»»»Ò¤È¤¤¤¦¥á¥½¥Ã¥Éµ¯Æ°¤Î¤¿¤á¤ÎÆÃÊ̤Êʸˡ¤¬ +I<¤¢¤ê¤Þ¤¹>¡£ +¸å¤Ë¤³¤ì¤Ë´Ø¤¹¤ë¾ÜºÙ¤ò¼è¤ê¾å¤²¤Þ¤¹¡£ + +=begin original + +Most methods you write will expect to operate on objects: + +=end original + +¤¢¤Ê¤¿¤Î½ñ¤¯¤Û¤È¤ó¤É¤Î¥á¥½¥Ã¥É¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤òÁàºî¤¹¤ë¤³¤È¤òÁÛÄꤷ¤Þ¤¹: + + sub save { + my $self = shift; + + open my $fh, '>', $self->path() or die $!; + print {$fh} $self->data() or die $!; + close $fh or die $!; + } + +=head2 Method Invocation +X<invocation> X<method> X<arrow> X<< -> >> + +(¥á¥½¥Ã¥É¤Îµ¯Æ°) + +=begin original + +Calling a method on an object is written as C<< $object->method >>. + +=end original + +¥ª¥Ö¥¸¥§¥¯¥È¤Î¥á¥½¥Ã¥É¤Î¸Æ¤Ó½Ð¤·¤Ï C<< $object->method >> ¤Î¤è¤¦¤Ë½ñ¤±¤Þ¤¹¡£ + +=begin original + +The left hand side of the method invocation (or arrow) operator is the +object (or class name), and the right hand side is the method name. + +=end original + +¥á¥½¥Ã¥Éµ¯Æ° (¤Ä¤Þ¤êÌð°õ) ±é»»»Ò¤Îº¸Â¦¤Ï¥ª¥Ö¥¸¥§¥¯¥È(¤Þ¤¿¤Ï¥á¥½¥Ã¥É̾)¤Ç¡¢ +±¦Â¦¤Ï¥á¥½¥Ã¥É̾¤Ç¤¹¡£ + + my $pod = File->new( 'perlobj.pod', $data ); + $pod->save(); + +=begin original + +The C<< -> >> syntax is also used when dereferencing a reference. It +looks like the same operator, but these are two different operations. + +=end original + +C<< -> >> ʸˡ¤Ï¡¢¥ê¥Õ¥¡¥ì¥ó¥¹¤ò¥Ç¥ê¥Õ¥¡¥ì¥ó¥¹¤¹¤ë¤¿¤á¤Ë¤â»È¤ï¤ì¤Þ¤¹¡£ +¤³¤ì¤ÏƱ¤¸±é»»»Ò¤Î¤è¤¦¤Ë¸«¤¨¤Þ¤¹¤¬¡¢¤³¤ì¤é¤ÏÆó¤Ä¤Î°Û¤Ê¤Ã¤¿½èÍý¤Ç¤¹¡£ + +=begin original + +When you call a method, the thing on the left side of the arrow is +passed as the first argument to the method. That means when we call C<< +Critter->new() >>, the C<new()> method receives the string C<"Critter"> +as its first argument. When we call C<< $fred->speak() >>, the C<$fred> +variable is passed as the first argument to C<speak()>. + +=end original + +¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹¤È¤¡¢Ìð°õ¤Îº¸Â¦¤Î¤â¤Î¤¬¥á¥½¥Ã¥É¤ÎºÇ½é¤Î°ú¿ô¤È¤·¤Æ +ÅϤµ¤ì¤Þ¤¹¡£ +¤Ä¤Þ¤ê¡¢C<< Critter->new() >> ¤ò¸Æ¤Ó½Ð¤¹¤È¡¢ +C<new()> ¥á¥½¥Ã¥É¤ÏºÇ½é¤Î°ú¿ô¤È¤·¤Æʸ»úÎó C<"Critter"> ¤ò¼õ¤±¼è¤ê¤Þ¤¹¡£ +C<< $fred->speak() >> ¤ò¸Æ¤Ó½Ð¤¹¤È¡¢ +C<$fred> ÊÑ¿ô¤¬ C<speak()> ¤ÎºÇ½é¤Î°ú¿ô¤È¤·¤ÆÅϤµ¤ì¤Þ¤¹¡£ + +=begin original + +Just as with any Perl subroutine, all of the arguments passed in C<@_> +are aliases to the original argument. This includes the object itself. +If you assign directly to C<$_[0]> you will change the contents of the +variable that holds the reference to the object. We recommend that you +don't do this unless you know exactly what you're doing. + +=end original + +¾¤Î Perl ¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¤ÈƱÍÍ¡¢C<@_> ¤ÇÅϤµ¤ì¤ëÁ´¤Æ¤Î°ú¿ô¤Ï +¸µ¤Î°ú¿ô¤Ø¤ÎÊÌ̾¤Ç¤¹¡£ +¤³¤ì¤Ë¤Ï¥ª¥Ö¥¸¥§¥¯¥È¼«¿È¤â´Þ¤Þ¤ì¤Þ¤¹¡£ +If you assign directly to +C<$_[0]> ¤ËľÀÜÂåÆþ¤¹¤ë¤È¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò +ÊÝ»ý¤·¤Æ¤¤¤ëÊÑ¿ô¤ÎÆâÍƤòÊѹ¹¤·¤Þ¤¹¡£ +¤¢¤Ê¤¿¤¬²¿¤ò¤·¤Æ¤¤¤ë¤Î¤«¤òÀµ³Î¤Ëʬ¤«¤Ã¤Æ¤¤¤Ê¤¤¸Â¤ê¡¢ +¤³¤ì¤ò¤·¤Ê¤¤¤³¤È¤ò´«¤á¤Þ¤¹¡£ + +=begin original + +Perl knows what package the method is in by looking at the left side of +the arrow. If the left hand side is a package name, it looks for the +method in that package. If the left hand side is an object, then Perl +looks for the method in the package that the object has been blessed +into. + +=end original + +Perl ¤Ï¡¢Ìð°õ¤Îº¸Â¦¤ò¸«¤ë¤³¤È¤Ç¡¢¥á¥½¥Ã¥É¤¬¤É¤Î¥Ñ¥Ã¥±¡¼¥¸¤Ë¤¢¤ë¤«¤òÃΤê¤Þ¤¹¡£ +º¸Â¦¤¬¥Ñ¥Ã¥±¡¼¥¸Ì¾¤Ê¤é¡¢¤½¤Î¥Ñ¥Ã¥±¡¼¥¸¤Î¥á¥½¥Ã¥É¤òõ¤·¤Þ¤¹¡£ +º¸Â¦¤¬¥ª¥Ö¥¸¥§¥¯¥È¤Ê¤é¡¢Perl ¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤Ë bless ¤µ¤ì¤Æ¤¤¤ë +¥Ñ¥Ã¥±¡¼¥¸¤Î¥á¥½¥Ã¥É¤òõ¤·¤Þ¤¹¡£ + +=begin original + +If the left hand side is neither a package name nor an object, then the +method call will cause an error, but see the section on L</Method Call +Variations> for more nuances. + +=end original + +º¸Â¦¤¬¥Ñ¥Ã¥±¡¼¥¸Ì¾¤Ç¤â¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤â¤Ê¤¤¾ì¹ç¡¢¥á¥½¥Ã¥É¸Æ¤Ó½Ð¤·¤Ï +¥¨¥é¡¼¤Ë¤Ê¤ê¤Þ¤¹¤¬¡¢¤µ¤é¤Ê¤ë¥Ë¥å¥¢¥ó¥¹¤Ë¤Ä¤¤¤Æ¤Ï +L</Method Call Variations> ¤ÎÀâ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=head2 Inheritance +X<inheritance> + +(·Ñ¾µ) + +=begin original + +We already talked about the special C<@ISA> array and the L<parent> +pragma. + +=end original + +ÆÃÊÌ¤Ê C<@ISA> ÇÛÎó¤È L<parent> ¥×¥é¥°¥Þ¤Ë¤Ä¤¤¤Æ¤Ï´û¤ËÏä·¤Þ¤·¤¿¡£ + +=begin original + +When a class inherits from another class, any methods defined in the +parent class are available to the child class. If you attempt to call a +method on an object that isn't defined in its own class, Perl will also +look for that method in any parent classes it may have. + +=end original + +¤¢¤ë¥¯¥é¥¹¤¬Â¾¤Î¥¯¥é¥¹¤ò·Ñ¾µ¤¹¤ë¤È¡¢¿Æ¥¯¥é¥¹¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤É¤Î¥á¥½¥Ã¥É¤â +»Ò¥¯¥é¥¹¤ÇÍøÍѲÄǽ¤Ç¤¹¡£ +¤¢¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¼«Ê¬¼«¿È¤Î¥¯¥é¥¹¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¥á¥½¥Ã¥É¤ò +¸Æ¤Ó½Ð¤½¤¦¤È¤¹¤ë¤È¡¢Perl ¤Ï¿Æ¥¯¥é¥¹¤Ë¤¢¤ë¥á¥½¥Ã¥É¤âõ¤·¤Þ¤¹¡£ + + package File::MP3; + use parent 'File'; # sets @File::MP3::ISA = ('File'); + + my $mp3 = File::MP3->new( 'Andvari.mp3', $data ); + $mp3->save(); + +=begin original + +Since we didn't define a C<save()> method in the C<File::MP3> class, +Perl will look at the C<File::MP3> class's parent classes to find the +C<save()> method. If Perl cannot find a C<save()> method anywhere in +the inheritance hierarchy, it will die. + +=end original + +C<File::MP3> ¥¯¥é¥¹¤Ë C<save()> ¥á¥½¥Ã¥É¤òÄêµÁ¤·¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢ +Perl ¤Ï C<save()> ¥á¥½¥Ã¥É¤ò¸«¤Ä¤±¤ë¤¿¤á¤Ë C<File::MP3> ¥¯¥é¥¹¤Î +¿Æ¥¯¥é¥¹¤ò¸«¤Þ¤¹¡£ +Perl ¤¬·Ñ¾µ³¬ÁؤΤɤ³¤Ë¤â C<save()> ¥á¥½¥Ã¥É¤ò¸«¤Ä¤±¤é¤ì¤Ê¤¤¤È¡¢ +die ¤·¤Þ¤¹¡£ + +=begin original + +In this case, it finds a C<save()> method in the C<File> class. Note +that the object passed to C<save()> in this case is still a +C<File::MP3> object, even though the method is found in the C<File> +class. + +=end original + +¤³¤Î¾ì¹ç¡¢C<File> ¥¯¥é¥¹¤Î C<save()> ¥á¥½¥Ã¥É¤ò¸«¤Ä¤±¤Þ¤¹¡£ +¤³¤Î¾ì¹ç¡¢¥á¥½¥Ã¥É¤Ï C<File> ¥¯¥é¥¹¤Ç¸«¤Ä¤«¤Ã¤¿¤È¤·¤Æ¤â¡¢ +C<save()> ¤ËÅϤµ¤ì¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ï¤ä¤Ï¤ê C<File::MP3> ¤Ç¤¢¤ë¤³¤È¤Ë +Ãí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=begin original + +We can override a parent's method in a child class. When we do so, we +can still call the parent class's method with the C<SUPER> +pseudo-class. + +=end original + +»Ò¥¯¥é¥¹¤Î¥á¥½¥Ã¥É¤Ç¿Æ¥¯¥é¥¹¤Î¥á¥½¥Ã¥É¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤Ç¤¤Þ¤¹¡£ +¤½¤¦¤·¤¿¤È¤¡¢C<SUPER> µ¿»÷¥¯¥é¥¹¤Ç¿Æ¥¯¥é¥¹¤Î¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤â +½ÐÍè¤Þ¤¹¡£ + + sub save { + my $self = shift; + + say 'Prepare to rock'; + $self->SUPER::save(); + } + +=begin original + +The C<SUPER> modifier can I<only> be used for method calls. You can't +use it for regular subroutine calls or class methods: + +=end original + +C<SUPER> ½¤¾þ»Ò¤Ï¥á¥½¥Ã¥É¸Æ¤Ó½Ð¤·¤Ç I<¤Î¤ß> »È¤¨¤Þ¤¹¡£ +Ä̾ï¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¸Æ¤Ó½Ð¤·¤ä¥¯¥é¥¹¥á¥½¥Ã¥É¤Ç¤Ï»È¤¨¤Þ¤»¤ó: + + SUPER::save($thing); # FAIL: looks for save() sub in package SUPER + + SUPER->save($thing); # FAIL: looks for save() method in class + # SUPER + + $thing->SUPER::save(); # Okay: looks for save() method in parent + # classes + +=head3 How SUPER is Resolved +X<SUPER> + +(SUPER ¤Ï¤É¤Î¤è¤¦¤Ë²ò·è¤µ¤ì¤ë¤«) + +=begin original + +The C<SUPER> pseudo-class is resolved from the package where the call +is made. It is I<not> resolved based on the object's class. This is +important, because it lets methods at different levels within a deep +inheritance hierarchy each correctly call their respective parent +methods. + +=end original + +C<SUPER> µ¿»÷¥¯¥é¥¹¤Ï¡¢¸Æ¤Ó½Ð¤·¤¬¹Ô¤ï¤ì¤¿¥Ñ¥Ã¥±¡¼¥¸¤«¤é²ò·è¤µ¤ì¤Þ¤¹¡£ +¤³¤ì¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¯¥é¥¹¤ò¸µ¤Ë¤·¤Æ²ò·è I<¤µ¤ì¤Þ¤»¤ó> ¡£ +¤³¤ì¤Ï½ÅÍפǤ¹; ¤Ê¤¼¤Ê¤é¤³¤ì¤Ë¤è¤ê +¿¼¤¤·Ñ¾µ³¬ÁؤǤ½¤ì¤¾¤ì°Û¤Ê¤Ã¤¿¥ì¥Ù¥ë¤Ë¤¢¤ë¥á¥½¥Ã¥É¤¬ +¤½¤ì¤¾¤ì¤Î¿Æ¥á¥½¥Ã¥É¤òÀµ¤·¤¯¸Æ¤Ó½Ð¤»¤ë¤è¤¦¤Ë¤Ê¤ë¤«¤é¤Ç¤¹¡£ + + package A; + + sub new { + return bless {}, shift; + } + + sub speak { + my $self = shift; + + $self->SUPER::speak(); + + say 'A'; + } + + package B; + + use parent 'A'; + + sub speak { + my $self = shift; + + $self->SUPER::speak(); + + say 'B'; + } + + package C; + + use parent 'B'; + + sub speak { + my $self = shift; + + $self->SUPER::speak(); + + say 'C'; + } + + my $c = C->new(); + $c->speak(); + +=begin original + +In this example, we will get the following output: + +=end original + +¤³¤ÎÎã¤Ç¤Ï¡¢¼¡¤Î¤è¤¦¤Ê½ÐÎϤˤʤê¤Þ¤¹: + + A + B + C + +=begin original + +This demonstrates how C<SUPER> is resolved. Even though the object is +blessed into the C<C> class, the C<speak()> method in the C<B> class +can still call C<SUPER::speak()> and expect it to correctly look in the +parent class of C<B> (i.e the class the method call is in), not in the +parent class of C<C> (i.e. the class the object belongs to). + +=end original + +¤³¤ì¤Ï¤É¤Î¤è¤¦¤Ë C<SUPER> ¤¬²ò·è¤µ¤ì¤ë¤«¤ò¿Þ¼¨¤·¤Þ¤¹¡£ +¤¿¤È¤¨¥ª¥Ö¥¸¥§¥¯¥È¤¬ C<C> ¥¯¥é¥¹¤Ë bless ¤µ¤ì¤Æ¤¤¤Æ¤â¡¢ +C<B> ¥¯¥é¥¹¤Î C<speak()> ¥á¥½¥Ã¥É¤Ï¤Þ¤À +C<SUPER::speak()> ¤ò¸Æ¤Ó½Ð¤·¤Æ¡¢Àµ¤·¤¯ C<B> (¤Ä¤Þ¤ê¥á¥½¥Ã¥É¸Æ¤Ó½Ð¤·¤µ¤ì¤¿ +¥¯¥é¥¹)¤Î¿Æ¥¯¥é¥¹¤ò¸«¤ë¤³¤È¤òÁÛÄꤷ¤Þ¤¹; +C<C> (¤Ä¤Þ¤ê¥ª¥Ö¥¸¥§¥¯¥È¤¬Â°¤¹¤ë¥¯¥é¥¹) ¤Î¿Æ¥¯¥é¥¹¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£ + +=begin original + +There are rare cases where this package-based resolution can be a +problem. If you copy a subroutine from one package to another, C<SUPER> +resolution will be done based on the original package. + +=end original + +¤³¤Î¥Ñ¥Ã¥±¡¼¥¸¤ò´ð¤Ë¤·¤¿²ò·è¤¬ÌäÂê¤Ë¤Ê¤ëµ©¤Ê¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¡£ +¥µ¥Ö¥ë¡¼¥Á¥ó¤ò¤¢¤ë¥Ñ¥Ã¥±¡¼¥¸¤«¤é¾¤Ë¥³¥Ô¡¼¤¹¤ë¤È¡¢ +C<SUPER> ¤Î²ò·è¤Ï¸µ¤Î¥Ñ¥Ã¥±¡¼¥¸¤ò´ð¤Ë¤·¤Æ¹Ô¤ï¤ì¤Þ¤¹¡£ + +=head3 Multiple Inheritance +X<multiple inheritance> + +(¿½Å·Ñ¾µ) + +=begin original + +Multiple inheritance often indicates a design problem, but Perl always +gives you enough rope to hang yourself with if you ask for it. + +=end original + +¤À½Å·Ú½ý¤Ï¤·¤Ð¤·¤ÐÀß·×¾å¤ÎÌäÂê¤òɽ¤·¤Þ¤¹¤¬¡¢¤·¤«¤·¤¢¤Ê¤¿¤¬µá¤á¤ë¤Ê¤é¡¢ +Perl ¤Ï¾ï¤Ë¤¢¤Ê¤¿¼«¿È¤¬¤Ö¤é²¼¤¬¤ë¤Î¤Ë½½Ê¬¤Ê¥í¡¼¥×¤òÍ¿¤¨¤Þ¤¹¡£ + +=begin original + +To declare multiple parents, you simply need to pass multiple class +names to C<use parent>: + +=end original + +¿½Å·Ñ¾µ¤òÀë¸À¤¹¤ë¤Ë¤Ï¡¢ +ñ¤ËÊ£¿ô¤Î¥¯¥é¥¹Ì¾¤ò C<use parent> ¤ËÅϤ¹É¬Íפ¬¤¢¤ê¤Þ¤¹: + + package MultiChild; + + use parent 'Parent1', 'Parent2'; + +=head3 Method Resolution Order +X<method resolution order> X<mro> + +(¥á¥½¥Ã¥É²ò·è½ç½ø) + +=begin original + +Method resolution order only matters in the case of multiple +inheritance. In the case of single inheritance, Perl simply looks up +the inheritance chain to find a method: + +=end original + +¥á¥½¥Ã¥É²ò·è½ç½ø¤Ï¿½Å·Ñ¾µ¤Î¾ì¹ç¤Ë¤Î¤ßÌäÂê¤Ë¤Ê¤ê¤Þ¤¹¡£ +ñ°ì·Ñ¾µ¤Î¾ì¹ç¤Ï¡¢Perl ¤Ï¥á¥½¥Ã¥É¤ò¸«¤Ä¤±¤ë¤¿¤á¤Ëñ½ã¤Ë·Ñ¾µ¥Á¥§¡¼¥ó¤ò +õ¤·¤Þ¤¹: + + Grandparent + | + Parent + | + Child + +=begin original + +If we call a method on a C<Child> object and that method is not defined +in the C<Child> class, Perl will look for that method in the C<Parent> +class and then, if necessary, in the C<Grandparent> class. + +=end original + +C<Child> ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤·¤Æ¡¢¤½¤Î¥á¥½¥Ã¥É¤¬ +C<Child> ¥¯¥é¥¹¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢ +Perl ¤ÏC<Parent> ¥¯¥é¥¹¤Î¥á¥½¥Ã¥É¤òõ¤·¡¢ +¤½¤ì¤«¤é¤â¤·É¬Íפʤé C<Grandparent> ¥¯¥é¥¹¤òõ¤·¤Þ¤¹¡£ + +=begin original + +If Perl cannot find the method in any of these classes, it will die +with an error message. + +=end original + +Perl ¤¬¤³¤ì¤é¤Î¥¯¥é¥¹¤Î¤É¤³¤«¤é¤â¤³¤Î¥á¥½¥Ã¥É¤ò¸«¤Ä¤±¤é¤ì¤Ê¤¤¾ì¹ç¡¢ +¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤È¶¦¤Ë die ¤·¤Þ¤¹¡£ + +=begin original + +When a class has multiple parents, the method lookup order becomes more +complicated. + +=end original + +¥¯¥é¥¹¤¬Ê£¿ô¤Î¿Æ¤ò»ý¤Ä¤È¤¡¢¥á¥½¥Ã¥É¸¡º÷½ç½ø¤Ï¤è¤êÊ£»¨¤Ë¤Ê¤ê¤Þ¤¹¡£ + +=begin original + +By default, Perl does a depth-first left-to-right search for a method. +That means it starts with the first parent in the C<@ISA> array, and +then searches all of its parents, grandparents, etc. If it fails to +find the method, it then goes to the next parent in the original +class's C<@ISA> array and searches from there. + +=end original + +¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢Perl ¤Ï¥á¥½¥Ã¥É¤ËÂФ·¤Æ¿¼¤µÍ¥À躸¤«¤é±¦Ãµº÷¤ò¹Ô¤¤¤Þ¤¹¡£ +¤Ä¤Þ¤ê¡¢C<@ISA> ÇÛÎó¤ÎºÇ½é¤Î¿Æ¤«¤é»Ï¤á¡¢¤½¤ì¤«¤é¤½¤ÎÁ´¤Æ¤Î¿Æ¡¢ÁÄÉãÊì¡¢ +¤È¤¤¤¦¤è¤¦¤Ëõº÷¤·¤Þ¤¹¡£ +¥á¥½¥Ã¥É¤ò¸«¤Ä¤±¤ë¤³¤È¤Ë¼ºÇÔ¤¹¤ë¤È¡¢¸µ¤Î¥¯¥é¥¹¤Î C<@ISA> ÇÛÎó¤Î +¼¡¤Î¿Æ¤Ë¹Ô¤¡¢¤½¤³¤«¤éõº÷¤·¤Þ¤¹¡£ + + SharedGreatGrandParent + / \ + PaternalGrandparent MaternalGrandparent + \ / + Father Mother + \ / + Child + +=begin original + +So given the diagram above, Perl will search C<Child>, C<Father>, +C<PaternalGrandparent>, C<SharedGreatGrandParent>, C<Mother>, and +finally C<MaternalGrandparent>. This may be a problem because now we're +looking in C<SharedGreatGrandParent> I<before> we've checked all its +derived classes (i.e. before we tried C<Mother> and +C<MaternalGrandparent>). + +=end original + +½¾¤Ã¤Æ¡¢Á°½Ò¤·¤¿¿Þ¤Î¾ì¹ç¡¢Perl ¤Ï +C<Child>, C<Father>, C<PaternalGrandparent>, C<SharedGreatGrandParent>, +C<Mother> ¤½¤·¤ÆºÇ¸å¤Ë C<MaternalGrandparent> ¤òõº÷¤·¤Þ¤¹¡£ +¤³¤ì¤Ï C<SharedGreatGrandParent> ¥¯¥é¥¹¤ò¡¢¤½¤ÎÁ´¤Æ¤ÎÇÉÀ¸¥¯¥é¥¹¤ò +¥Á¥§¥Ã¥¯¤¹¤ë (¤Ä¤Þ¤ê C<Mother> ¤È C<MaternalGrandparent> ¤ò»î¤¹) I<Á°¤Ë> +¸«¤ë¤Î¤Ç¡¢ÌäÂ꤬¤¢¤ë¤«¤âÃΤì¤Þ¤»¤ó¡£ + +=begin original + +It is possible to ask for a different method resolution order with the +L<mro> pragma. + +=end original + +L<mro> ¥×¥é¥°¥Þ¤Ç°Û¤Ê¤Ã¤¿¥á¥½¥Ã¥É²ò·è½ç½ø¤ò»È¤¦¤è¤¦¤Ë¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£ + + package Child; + + use mro 'c3'; + use parent 'Father', 'Mother'; + +=begin original + +This pragma lets you switch to the "C3" resolution order. In simple +terms, "C3" order ensures that shared parent classes are never searched +before child classes, so Perl will now search: C<Child>, C<Father>, +C<PaternalGrandparent>, C<Mother> C<MaternalGrandparent>, and finally +C<SharedGreatGrandParent>. Note however that this is not +"breadth-first" searching: All the C<Father> ancestors (except the +common ancestor) are searched before any of the C<Mother> ancestors are +considered. + +=end original + +¤³¤Î¥×¥é¥°¥Þ¤Ï "C3" ²ò·è½ç½ø¤ËÀÚ¤êÂؤ¨¤Þ¤¹¡£ +´Êñ¤Ë¸À¤¨¤Ð¡¢"C3" ½ç½ø¤Ï +¶¦Í¿Æ¥¯¥é¥¹¤¬»Ò¥¯¥é¥¹¤è¤êÀè¤Ëõº÷¤µ¤ì¤Ê¤¤¤³¤È¤òÊݾڤ¹¤ë¤Î¤Ç¡¢ +Perl ¤Ï¼¡¤Î½ç¤Çõº÷¤¹¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹: +C<Child>, C<Father>, +C<PaternalGrandparent>, C<Mother> C<MaternalGrandparent> ¤½¤·¤ÆºÇ¸å¤Ë +C<SharedGreatGrandParent>¡£ +¤·¤«¤·¡¢¤³¤ì¤Ï¡ÖÉýÍ¥Àè¡×õº÷¤Ç¤Ï¤Ê¤¤¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤: +arching: All the +(¶¦Ä̤ÎÁÄÀè¤ò½ü¤¯) Á´¤Æ¤Î C<Father> ¤ÎÁÄÀè¤Ï¡¢ +C<Mother> ¤ÎÁÄÀè¤è¤êÁ°¤Ëõº÷¤µ¤ì¤Þ¤¹¡£ + +=begin original + +The C3 order also lets you call methods in sibling classes with the +C<next> pseudo-class. See the L<mro> documentation for more details on +this feature. + +=end original + +C3 ½ç½ø¤Ï¤Þ¤¿¡¢C<next> µ¿»÷¥¯¥é¥¹¤Ç·»Ä說¥é¥¹¤Î¥á¥½¥Ã¥É¤ò +¸Æ¤Ó½Ð¤»¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£ +¤³¤Îµ¡Ç½¤Ë´Ø¤¹¤ë¤µ¤é¤Ê¤ë¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï L<mro> ʸ½ñ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=head3 Method Resolution Caching + +(¥á¥½¥Ã¥É²ò·è¥¥ã¥Ã¥·¥å) + +=begin original + +When Perl searches for a method, it caches the lookup so that future +calls to the method do not need to search for it again. Changing a +class's parent class or adding subroutines to a class will invalidate +the cache for that class. + +=end original + +Perl ¤¬¥á¥½¥Ã¥É¤òõ¤¹¤È¤¡¢·ë²Ì¤ò¥¥ã¥Ã¥·¥å¤¹¤ë¤Î¤Ç¡¢ +¤½¤Î¥á¥½¥Ã¥É¤ò¾Íè¸Æ¤Ó½Ð¤·¤Æ¤âºÆ¤Óõ¤¹É¬ÍפϤ¢¤ê¤Þ¤»¤ó¡£ +¥¯¥é¥¹¤Î¿Æ¥¯¥é¥¹¤¬Êѹ¹¤µ¤ì¤¿¤ê¡¢¥¯¥é¥¹¤Ë¥µ¥Ö¥ë¡¼¥Á¥ó¤¬Äɲ䵤ì¤ë¤È¡¢ +¤½¤Î¥¯¥é¥¹¤Î¥¥ã¥Ã¥·¥å¤Ï̵¸ú²½¤µ¤ì¤Þ¤¹¡£ + +=begin original + +The L<mro> pragma provides some functions for manipulating the method +cache directly. + +=end original + +L<mro> ¥×¥é¥°¥Þ¤Ï¥á¥½¥Ã¥É¥¥ã¥Ã¥·¥å¤òľÀÜÁàºî¤¹¤ë¤¿¤á¤Î +¤¤¤¯¤Ä¤«¤Î´Ø¿ô¤òÄ󶡤·¤Þ¤¹¡£ + +=head2 Writing Constructors +X<constructor> + +(¥³¥ó¥¹¥È¥é¥¯¥¿¤ò½ñ¤¯) + +=begin original + +As we mentioned earlier, Perl provides no special constructor syntax. +This means that a class must implement its own constructor. A +constructor is simply a class method that returns a reference to a new +object. + +=end original + +Á°½Ò¤·¤¿¤è¤¦¤Ë¡¢Perl ¤Ï¥³¥ó¥¹¥È¥é¥¯¥¿¤Î¤¿¤á¤ÎÆÃÊ̤Êʸˡ¤òÄ󶡤·¤Þ¤»¤ó¡£ +¤Ä¤Þ¤ê¡¢¥¯¥é¥¹¤Ï¼«¿È¤Î¥³¥ó¥¹¥È¥é¥¯¥¿¤ò¼ÂÁõ¤·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£ +¥³¥ó¥¹¥È¥é¥¯¥¿¤Ï¿·¤·¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤òÊÖ¤¹Ã±¤Ê¤ë +¥¯¥é¥¹¥á¥½¥Ã¥É¤Ç¤¹¡£ + +=begin original + +The constructor can also accept additional parameters that define the +object. Let's write a real constructor for the C<File> class we used +earlier: + +=end original + +¥³¥ó¥¹¥È¥é¥¯¥¿¤Ï¤Þ¤¿¡¢¥ª¥Ö¥¸¥§¥¯¥È¤òÄêµÁ¤¹¤ë¤¿¤á¤ÎÄɲäΰú¿ô¤ò¼õ¤±¼è¤ì¤Þ¤¹¡£ +°ÊÁ°¤Ë»È¤Ã¤¿ C<File> ¥¯¥é¥¹¤Î¼ÂºÝ¤Î¥³¥ó¥¹¥È¥é¥¯¥¿¤ò½ñ¤¤¤Æ¤ß¤Þ¤·¤ç¤¦: + + package File; + + sub new { + my $class = shift; + my ( $path, $data ) = @_; + + my $self = bless { + path => $path, + data => $data, + }, $class; + + return $self; + } + +=begin original + +As you can see, we've stored the path and file data in the object +itself. Remember, under the hood, this object is still just a hash. +Later, we'll write accessors to manipulate this data. + +=end original + +¤³¤³¤Ç¸«¤é¤ì¤ë¤è¤¦¤Ë¡¢¥Ñ¥¹¤È¥Õ¥¡¥¤¥ë¥Ç¡¼¥¿¤ò¥ª¥Ö¥¸¥§¥¯¥È¼«¿È¤Ë +Êݴɤ·¤Æ¤¤¤Þ¤¹¡£ +¿åÌ̲¼¤Ç¤Ï¡¢¤³¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ï¤Þ¤Àñ¤Ê¤ë¥Ï¥Ã¥·¥å¤Ç¤¢¤ë¤³¤È¤ò +˺¤ì¤Ê¤¤¤Ç¤¯¤À¤µ¤¤¡£ +¸å¤Ç¡¢¤³¤Î¥Ç¡¼¥¿¤òÁàºî¤¹¤ë¤¿¤á¤Î¥¢¥¯¥»¥µ¤ò½ñ¤¤Þ¤¹¡£ + +=begin original + +For our File::MP3 class, we can check to make sure that the path we're +given ends with ".mp3": + +=end original + +¤³¤Î File::MP3 ¥¯¥é¥¹¤Î¤¿¤á¤Ë¡¢Í¿¤¨¤é¤ì¤¿¥Ñ¥¹¤¬ ".mp3" ¤Ç½ª¤ï¤Ã¤Æ¤¤¤ë¤«¤ò +¥Á¥§¥Ã¥¯¤Ç¤¤Þ¤¹: + + package File::MP3; + + sub new { + my $class = shift; + my ( $path, $data ) = @_; + + die "You cannot create a File::MP3 without an mp3 extension\n" + unless $path =~ /\.mp3\z/; + + return $class->SUPER::new(@_); + } + +=begin original + +This constructor lets its parent class do the actual object +construction. + +=end original + +¤³¤Î¥³¥ó¥¹¥È¥é¥¯¥¿¤Ï¿Æ¥¯¥é¥¹¤Ë¼ÂºÝ¤Î¥ª¥Ö¥¸¥§¥¯¥È¹½ÃÛ¤ò¹Ô¤ï¤»¤Þ¤¹¡£ + +=head2 Attributes +X<attribute> + +(°À) + +=begin original + +An attribute is a piece of data belonging to a particular object. +Unlike most object-oriented languages, Perl provides no special syntax +or support for declaring and manipulating attributes. + +=end original + +°À¤ÏÆÃÄê¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ë½ê°¤¹¤ë¥Ç¡¼¥¿ÊҤǤ¹¡£ +¤Û¤È¤ó¤É¤Î¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ¸À¸ì¤È°Û¤Ê¤ê¡¢Perl ¤Ï°À¤ÎÀë¸À¤äÁàºî¤Ë +Âбþ¤¹¤ëÆÃÊ̤Êʸˡ¤òÄ󶡤·¤Þ¤»¤ó¡£ + +=begin original + +Attributes are often stored in the object itself. For example, if the +object is an anonymous hash, we can store the attribute values in the +hash using the attribute name as the key. + +=end original + +°À¤Ï¤·¤Ð¤·¤Ð¥ª¥Ö¥¸¥§¥¯¥È¼«¿È¤ËÊݴɤµ¤ì¤Þ¤¹¡£ +Î㤨¤Ð¡¢¥ª¥Ö¥¸¥§¥¯¥È¤¬ÌµÌ¾¥Ï¥Ã¥·¥å¤Ê¤é¡¢Â°À̾¤ò¥¡¼¤È¤·¤Æ»È¤Ã¤Æ +¤½¤Î¥Ï¥Ã¥·¥å¤Ë°ÀÃͤòÊݴɤǤ¤Þ¤¹¡£ + +=begin original + +While it's possible to refer directly to these hash keys outside of the +class, it's considered a best practice to wrap all access to the +attribute with accessor methods. + +=end original + +¤³¤ì¤é¤Î¥Ï¥Ã¥·¥å¥¡¼¤ò¥¯¥é¥¹¤Î³°Â¦¤«¤éľÀÜ»²¾È¤¹¤ë¤³¤È¤Ï²Äǽ¤Ç¤¹¤¬¡¢ +Á´¤Æ¤Î°À¤Ø¤Î¥¢¥¯¥»¥¹¤ò¥¢¥¯¥»¥µ¥á¥½¥Ã¥É¤ÇÊñ¤à¤Î¤¬¥Ù¥¹¥È¥×¥é¥¯¥Æ¥£¥¹¤È +¹Í¤¨¤é¤ì¤Æ¤¤¤Þ¤¹¡£ + +=begin original + +This has several advantages. Accessors make it easier to change the +implementation of an object later while still preserving the original +API. + +=end original + +¤³¤ì¤Ë¤Ï¤¤¤¯¤Ä¤«¤ÎÍøÅÀ¤¬¤¢¤ê¤Þ¤¹¡£ +¥¢¥¯¥»¥µ¤Ï¡¢¸å¤Ë¸µ¤Î API ¤òÊݸ¤·¤¿¤Þ¤Þ¥ª¥Ö¥¸¥§¥¯¥È¤Î¼ÂÁõ¤ò +Êѹ¹¤¹¤ë¤Î¤ò¤è¤ê´Êñ¤Ë¤·¤Þ¤¹¡£ + +=begin original + +An accessor lets you add additional code around attribute access. For +example, you could apply a default to an attribute that wasn't set in +the constructor, or you could validate that a new value for the +attribute is acceptable. + +=end original + +¥¢¥¯¥»¥µ¤Ï°À¥¢¥¯¥»¥¹¤Ë´Ø¤¹¤ëÄɲäΥ³¡¼¥É¤òÄɲäǤ¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£ +Î㤨¤Ð¡¢¥³¥ó¥¹¥È¥é¥¯¥¿¤ÇÀßÄꤵ¤ì¤Ê¤¤Â°À¤Î¥Ç¥Õ¥©¥ë¥È¤òŬÍѤ·¤¿¤ê¡¢ +°À¤Î¿·¤·¤¤Ãͤ¬¼õ¤±Æþ¤ì¤é¤ì¤ë¤«¤Î¸¡¾Ú¤ò¤·¤¿¤ê½ÐÍè¤Þ¤¹¡£ + +=begin original + +Finally, using accessors makes inheritance much simpler. Subclasses can +use the accessors rather than having to know how a parent class is +implemented internally. + +=end original + +ºÇ¸å¤Ë¡¢¥¢¥¯¥»¥µ¤ò»È¤¦¤È·Ñ¾µ¤¬ô£¤«¤Ë´Êñ¤Ë¤Ê¤ê¤Þ¤¹¡£ +¥µ¥Ö¥¯¥é¥¹¤Ï¥¢¥¯¥»¥µ¤ò»È¤¦¤³¤È¤Ç¡¢¿Æ¥¯¥é¥¹¤¬ÆâÉô¤Ç¤É¤Î¤è¤¦¤Ë +¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¤«¤òÃΤëɬÍפ¬¤Ê¤¯¤Ê¤ê¤Þ¤¹¡£ + +=head3 Writing Accessors +X<accessor> + +(¥¢¥¯¥»¥µ¤ò½ñ¤¯) + +=begin original + +As with constructors, Perl provides no special accessor declaration +syntax, so classes must provide explicitly written accessor methods. +There are two common types of accessors, read-only and read-write. + +=end original + +¥³¥ó¥¹¥È¥é¥¯¥¿¤ÈƱÍÍ¡¢Perl ¤ÏÆÃÊ̤ʥ¢¥¯¥»¥µÀë¸Àʸˡ¤ò»ý¤¿¤Ê¤¤¤Î¤Ç¡¢ +¥¯¥é¥¹¤ÏÌÀ¼¨Åª¤Ë½ñ¤«¤ì¤¿¥¢¥¯¥»¥µ¥á¥½¥Ã¥É¤òÄ󶡤·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£ +¥¢¥¯¥»¥µ¤Ë¤Ï 2 ¼ïÎढ¤ê¤Þ¤¹; Æɤ߹þ¤ßÀìÍѤÈÆɤ߽ñ¤ÍѤǤ¹¡£ + +=begin original + +A simple read-only accessor simply gets the value of a single +attribute: + +=end original + +ñ½ã¤ÊÆɤ߹þ¤ßÀìÍÑ¥¢¥¯¥»¥µ¤Ïñ½ã¤Ëñ°ì¤Î°À¤ÎÃͤò¼èÆÀ¤·¤Þ¤¹: + + sub path { + my $self = shift; + + return $self->{path}; + } + +=begin original + +A read-write accessor will allow the caller to set the value as well as +get it: + +=end original + +Æɤ߽ñ¤¥¢¥¯¥»¥µ¤Ï¡¢¸Æ¤Ó½Ð¤·Â¦¤¬¼èÆÀ¤È¶¦¤ËÃͤÎÀßÄê¤â¤Ç¤¤ë¤è¤¦¤Ë¤·¤Þ¤¹: + + sub path { + my $self = shift; + + if (@_) { + $self->{path} = shift; + } + + return $self->{path}; + } + +=head2 An Aside About Smarter and Safer Code + +(¤è¤ê¸¤¯°ÂÁ´¤Ê¥³¡¼¥É¤Î¤¿¤á¤Î;ÃÌ) + +=begin original + +Our constructor and accessors are not very smart. They don't check that +a C<$path> is defined, nor do they check that a C<$path> is a valid +filesystem path. + +=end original + +¤³¤Î¥³¥ó¥¹¥È¥é¥¯¥¿¤È¥¢¥¯¥»¥µ¤Ï¤¢¤Þ¤ê¸¤¯¤¢¤ê¤Þ¤»¤ó¡£ +C<$path> ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤«¤ò¥Á¥§¥Ã¥¯¤·¤Þ¤»¤ó¤·¡¢ +C<$path> ¤¬Í¸ú¤Ê¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¥Ñ¥¹¤«¤ò¥Á¥§¥Ã¥¯¤·¤Þ¤»¤ó¡£ + +=begin original + +Doing these checks by hand can quickly become tedious. Writing a bunch +of accessors by hand is also incredibly tedious. There are a lot of +modules on CPAN that can help you write safer and more concise code, +including the modules we recommend in L<perlootut>. + +=end original + +¤³¤ì¤é¤Î¥Á¥§¥Ã¥¯¤ò¼ê¤Ç½ñ¤¯¤Î¤Ï¤¹¤°¤ËÂà¶þ¤Ë¤Ê¤ê¤Þ¤¹¡£ +¤¿¤¯¤µ¤ó¤Î¥¢¥¯¥»¥µ¤ò¼ê¤Ç½ñ¤¯¤Î¤â¤È¤Æ¤âÂà¶þ¤Ç¤¹¡£ +¤è¤ê°ÂÁ´¤Ç¤è¤ê´Ê·é¤Ê¥³¡¼¥É¤ò½ñ¤¯¤³¤È¤ò½õ¤±¤ë¤¿¤á¤Î¡¢ +L<perlootut> ¤Ç¿ä¾©¤µ¤ì¤Æ¤¤¤ë¥â¥¸¥å¡¼¥ë¤ò´Þ¤à¿¤¯¤Î¥â¥¸¥å¡¼¥ë¤¬ +CPAN ¤Ë¤¢¤ê¤Þ¤¹¡£ + +=head2 Method Call Variations +X<method> + +(¥á¥½¥Ã¥É¸Æ¤Ó½Ð¤·¤Î¥Ð¥ê¥¨¡¼¥·¥ç¥ó) + +=begin original + +Perl supports several other ways to call methods besides the C<< +$object->method() >> usage we've seen so far. + +=end original + +Perl ¤Ë¤Ï C<< $object->method() >> ¤È¤¤¤¦»ÈÍÑË¡°Ê³°¤Ë¤â¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹ +ÊýË¡¤¬¤¤¤¯¤Ä¤«¤¢¤ë¤Î¤Ç¤½¤ì¤ò¸«¤Æ¤¤¤¤Þ¤¹¡£ + +=head3 Method Names as Strings + +(ʸ»úÎó¤È¤·¤Æ¤Î¥á¥½¥Ã¥É̾) + +=begin original + +Perl lets you use a scalar variable containing a string as a method +name: + +=end original + +Perl ¤Ïʸ»úÎó¤ò´Þ¤à¥¹¥«¥éÊÑ¿ô¤ò¥á¥½¥Ã¥É̾¤È¤·¤Æ»È¤¦¤³¤È¤òµö¤·¤Æ¤¤¤Þ¤¹: + + my $file = File->new( $path, $data ); + + my $method = 'save'; + $file->$method(); + +=begin original + +This works exactly like calling C<< $file->save() >>. This can be very +useful for writing dynamic code. For example, it allows you to pass a +method name to be called as a parameter to another method. + +=end original + +¤³¤ì¤ÏÀµ³Î¤Ë C<< $file->save() >> ¸Æ¤Ó½Ð¤·¤ÈƱÍͤǤ¹¡£ +¤³¤ì¤ÏưŪ¥³¡¼¥É¤ò½ñ¤¯¤Î¤Ë¤È¤Æ¤âÍÍѤǤ¹¡£ +Î㤨¤Ð¡¢Â¾¤Î¥á¥½¥Ã¥É¤Î°ú¿ô¤È¤·¤Æ¸Æ¤Ó½Ð¤µ¤ì¤ë¥á¥½¥Ã¥É̾¤òÅϤ»¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£ + +=head3 Class Names as Strings + +(ʸ»úÎó¤È¤·¤Æ¤Î¥¯¥é¥¹Ì¾) + +=begin original + +Perl also lets you use a scalar containing a string as a class name: + +=end original + +Perl ¤Ïʸ»úÎó¤ò´Þ¤à¥¹¥«¥é¤ò¥¯¥é¥¹Ì¾¤È¤·¤Æ»È¤¦¤³¤È¤òµö¤·¤Æ¤¤¤Þ¤¹: + + my $class = 'File'; + + my $file = $class->new( $path, $data ); + +=begin original + +Again, this allows for very dynamic code. + +=end original + +ºÆ¤Ó¡¢¤³¤ì¤Ë¤è¤ê¤È¤Æ¤âưŪ¤Ê¥³¡¼¥É¤¬½ñ¤±¤Þ¤¹¡£ + +=head3 Subroutine References as Methods + +(¥á¥½¥Ã¥É¤È¤·¤Æ¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¥ê¥Õ¥¡¥ì¥ó¥¹) + +=begin original + +You can also use a subroutine reference as a method: + +=end original + +¥µ¥Ö¥ë¡¼¥Á¥ó¥ê¥Õ¥¡¥ì¥ó¥¹¤ò¥á¥½¥Ã¥É¤È¤·¤Æ»È¤¦¤³¤È¤â½ÐÍè¤Þ¤¹: + + my $sub = sub { + my $self = shift; + + $self->save(); + }; + + $file->$sub(); + +=begin original + +This is exactly equivalent to writing C<< $sub->($file) >>. You may see +this idiom in the wild combined with a call to C<can>: + +=end original + +¤³¤ì¤Ï C<< $sub->($file) >> ¤È½ñ¤¯¤Î¤ÈÀµ³Î¤ËÅù²Á¤Ç¤¹¡£ +À¤¤ÎÃæ¤Ç¤Ï¤³¤Î´·ÍѶç¤ò C<can> ¤Î¸Æ¤Ó½Ð¤·¤È·ë¤Ó¤Ä¤±¤é¤ì¤Æ¤¤¤ë¤Î¤ò +¸«¤ë¤³¤È¤¬¤¢¤ë¤Ç¤·¤ç¤¦: + + if ( my $meth = $object->can('foo') ) { + $object->$meth(); + } + +=head3 Deferencing Method Call + +(¥á¥½¥Ã¥É¸Æ¤Ó½Ð¤·¤Î¥Ç¥ê¥Õ¥¡¥ì¥ó¥¹) + +=begin original + +Perl also lets you use a dereferenced scalar reference in a method +call. That's a mouthful, so let's look at some code: + +=end original + +Perl ¤Ï¤Þ¤¿¡¢¥á¥½¥Ã¥É¸Æ¤Ó½Ð¤·¤ÎÃæ¤Ç¥Ç¥ê¥Õ¥¡¥ì¥ó¥¹¤µ¤ì¤¿¥¹¥«¥é¥ê¥Õ¥¡¥ì¥ó¥¹¤ò +»È¤¦¤³¤È¤òµö¤·¤Æ¤¤¤Þ¤¹¡£ +¤³¤ì¤Ïʬ¤«¤ê¤Ë¤¯¤¤¤Î¤Ç¡¢¥³¡¼¥É¤ò¸«¤Æ¤¯¤À¤µ¤¤: + + $file->${ \'save' }; + $file->${ returns_scalar_ref() }; + $file->${ \( returns_scalar() ) }; + $file->${ returns_sub_ref() }; + +=begin original + +This works if the dereference produces a string I<or> a subroutine +reference. + +=end original + +¤³¤ì¤Ï¡¢¥Ç¥ê¥Õ¥¡¥ì¥ó¥¹¤¬Ê¸»úÎó I<¤Þ¤¿¤Ï> ¥µ¥Ö¥ë¡¼¥Á¥ó¥ê¥Õ¥¡¥ì¥ó¥¹¤ò +À¸À®¤¹¤ë¤È¤¤ËÆ°ºî¤·¤Þ¤¹¡£ + +=head3 Method Calls on Filehandles + +(¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ç¤Î¥á¥½¥Ã¥É¸Æ¤Ó½Ð¤·) + +=begin original + +Under the hood, Perl filehandles are instances of the C<IO::Handle> or +C<IO::File> class. Once you have an open filehandle, you can call +methods on it. Additionally, you can call methods on the C<STDIN>, +C<STDOUT>, and C<STDERR> filehandles. + +=end original + +¿åÌ̲¼¤Ç¤Ï¡¢Perl ¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ï C<IO::Handle> ¤Þ¤¿¤Ï +C<IO::File> ¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤Ç¤¹¡£ +°ìÅÙ¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ò³«¤¯¤È¡¢¤½¤Î¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤»¤Þ¤¹¡£ +¤µ¤é¤Ë¡¢C<STDIN>, C<STDOUT>, C<STDERR> ¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î¥á¥½¥Ã¥É¤ò +¸Æ¤Ó½Ð¤»¤Þ¤¹¡£ + + open my $fh, '>', 'path/to/file'; + $fh->autoflush(); + $fh->print('content'); + + STDOUT->autoflush(); + +=head2 Invoking Class Methods +X<invocation> + +(¥¯¥é¥¹¥á¥½¥Ã¥É¤Îµ¯Æ°) + +=begin original + +Because Perl allows you to use barewords for package names and +subroutine names, it sometimes interprets a bareword's meaning +incorrectly. For example, the construct C<< Class->new() >> can be +interpreted as either C<< 'Class'->new() >> or C<< Class()->new() >>. +In English, that second interpretation reads as "call a subroutine +named Class(), then call new() as a method on the return value of +Class()". If there is a subroutine named C<Class()> in the current +namespace, Perl will always interpret C<< Class->new() >> as the second +alternative: a call to C<new()> on the object returned by a call to +C<Class()> + +=end original + +Perl ¤Ï¥Ñ¥Ã¥±¡¼¥¸Ì¾¤È¥µ¥Ö¥ë¡¼¥Á¥ó̾¤ËÍç¤Îñ¸ì¤ò»È¤¦¤³¤È¤òµö¤·¤Æ¤¤¤ë¤Î¤Ç¡¢ +»þ¡¹Íç¤Îñ¸ì¤Î°ÕÌ£¤ò¸í¤Ã¤Æ²ò¼á¤·¤Þ¤¹¡£ +Î㤨¤Ð¡¢C<< Class->new() >> ¤È¤¤¤¦¹½Ê¸¤Ï¡¢ +C<< 'Class'->new() >> ¤Þ¤¿¤Ï C<< Class()->new() >> ¤Î¤É¤Á¤é¤Ç¤â²ò¼á¤Ç¤¤Þ¤¹¡£ +±Ñ¸ì¤Ç¤Ï¡¢2 ÈÖÌܤβò¼á¤Ï¡ÖClass() ¤È¤¤¤¦Ì¾Á°¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¤ò¸Æ¤Ó½Ð¤·¡¢ +¤½¤ì¤«¤é Class() ¤ÎÊÖ¤êÃͤΥ᥽¥Ã¥É¤È¤·¤Æ new() ¤ò¸Æ¤Ó½Ð¤¹¡×¤ÈÆɤá¤Þ¤¹¡£ +¸½ºß¤Î̾Á°¶õ´Ö¤Ë C<Class()> ¤È¤¤¤¦Ì¾Á°¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¤¬¤¢¤ë¾ì¹ç¡¢ +Perl ¤Ï¾ï¤Ë C<< Class->new() >> ¤ò 2 ÈÖÌܤÎÁªÂò»è¤Î¤è¤¦¤Ë²ò¼á¤·¤Þ¤¹: +C<Class()> ¤«¤éÊÖ¤µ¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥È¤Î C<new()> ¤ò¸Æ¤Ó½Ð¤·¤Þ¤¹¡£ + +=begin original + +You can force Perl to use the first interpretation (i.e. as a method +call on the class named "Class") in two ways. First, you can append a +C<::> to the class name: + +=end original + +Æó¤Ä¤ÎÊýË¡¤ÇºÇ½é¤Î²ò¼á (¤Ä¤Þ¤ê "Class" ¤È¤¤¤¦¥¯¥é¥¹¤Î¥á¥½¥Ã¥É¸Æ¤Ó½Ð¤·) ¤ò +Perl ¤Ë¶¯À©¤Ç¤¤Þ¤¹¡£ +¤Þ¤º¡¢C<::> ¤ò¥¯¥é¥¹Ì¾¤ËÄɲäǤ¤Þ¤¹: + + Class::->new() + +=begin original + +Perl will always interpret this as a method call. + +=end original + +Perl ¤Ï¾ï¤Ë¤³¤ì¤ò¥á¥½¥Ã¥É¸Æ¤Ó½Ð¤·¤È¤·¤Æ²ò¼á¤·¤Þ¤¹¡£ + +=begin original + +Alternatively, you can quote the class name: + +=end original + +¤¢¤ë¤¤¤Ï¡¢¥¯¥é¥¹Ì¾¤ò¥¯¥©¡¼¥È¤Ç¤¤Þ¤¹: + + 'Class'->new() + +=begin original + +Of course, if the class name is in a scalar Perl will do the right +thing as well: + +=end original + +¤â¤Á¤í¤ó¡¢¥¯¥é¥¹Ì¾¤¬¥¹¥«¥é¤Ç¤¢¤ì¤Ð Perl ¤ÏƱÍͤËÀµ¤·¤¤¤³¤È¤ò¹Ô¤¤¤Þ¤¹: + + my $class = 'Class'; + $class->new(); + +=head3 Indirect Object Syntax +X<indirect object> + +(´ÖÀÜ¥ª¥Ö¥¸¥§¥¯¥Èʸˡ) + +=begin original + +B<Outside of the file handle case, use of this syntax is discouraged, +as it can confuse the Perl interpreter. See below for more details.> + +=end original + +B<¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î¾ì¹ç¤ò½ü¤¤¤Æ¡¢¤³¤Îʸˡ¤Î»ÈÍѤÏÈó¿ä¾©¤Ç¤¹; +Perl ¥¤¥ó¥¿¥×¥ê¥¿¤òº®Í𤵤»¤ë¤³¤È¤¬¤¢¤ë¤«¤é¤Ç¤¹¡£ +¤µ¤é¤Ê¤ë¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï°Ê¹ß¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£> + +=begin original + +Perl suports another method invocation syntax called "indirect object" +notation. This syntax is called "indirect" because the method comes +before the object it is being invoked on. + +=end original + +Perl ¤Ï¡¢¡Ö´ÖÀÜ¥ª¥Ö¥¸¥§¥¯¥È¡×µË¡¤È¸Æ¤Ð¤ì¤ë¤â¤¦°ì¤Ä¤Î¥á¥½¥Ã¥Éµ¯Æ°Ê¸Ë¡¤Ë +Âбþ¤·¤Æ¤¤¤Þ¤¹¡£ +¤³¤Îʸˡ¤Ï¡¢µ¯Æ°¤µ¤ì¤ë¥ª¥Ö¥¸¥§¥¯¥È¤ÎÁ°¤Ë¥á¥½¥Ã¥É̾¤¬Íè¤ë¤Î¤Ç +¡Ö´ÖÀܡפȸƤФì¤Þ¤¹¡£ + +=begin original + +This syntax can be used with any class or object method: + +=end original + +¤³¤Îʸˡ¤ÏǤ°Õ¤Î¥¯¥é¥¹¤ª¤è¤Ó¥ª¥Ö¥¸¥§¥¯¥È¥á¥½¥Ã¥É¤Ç»È¤¨¤Þ¤¹: + + my $file = new File $path, $data; + save $file; + +=begin original + +We recommend that you avoid this syntax, for several reasons. + +=end original + +¤¤¤¯¤Ä¤«¤ÎÍýͳ¤Ë¤è¤ê¡¢¤³¤Îʸˡ¤ÏÈò¤±¤ë¤³¤È¤ò´«¤á¤Þ¤¹¡£ + +=begin original + +First, it can be confusing to read. In the above example, it's not +clear if C<save> is a method provided by the C<File> class or simply a +subroutine that expects a file object as its first argument. + +=end original + +¤Þ¤º¡¢¤³¤ì¤ÏÆɤà¤Î¤Ëº®Í𤹤뤳¤È¤¬¤¢¤ê¤Þ¤¹¡£ +Á°½Ò¤ÎÎã¤Ç¤Ï¡¢C<save> ¤¬ C<File> ¤Ë¤è¤Ã¤ÆÄ󶡤µ¤ì¤ë¥á¥½¥Ã¥É¤Ê¤Î¤« +ºÇ½é¤Î°ú¿ô¤È¤·¤Æ¥Õ¥¡¥¤¥ë¥ª¥Ö¥¸¥§¥¯¥È¤òÁÛÄꤹ¤ëñ¤Ê¤ë¥µ¥Ö¥ë¡¼¥Á¥ó¤Ê¤Î¤«¤¬ +¤Ï¤Ã¤¤ê¤·¤Þ¤»¤ó¡£ + +=begin original + +When used with class methods, the problem is even worse. Because Perl +allows subroutine names to be written as barewords, Perl has to guess +whether the bareword after the method is a class name or subroutine +name. In other words, Perl can resolve the syntax as either C<< +File->new( $path, $data ) >> B<or> C<< new( File( $path, $data ) ) >>. + +=end original + +¥¯¥é¥¹¥á¥½¥Ã¥É¤Ç»È¤¦¤È¤¡¢ÌäÂê¤Ï¤µ¤é¤Ë°¤¯¤Ê¤ê¤Þ¤¹¡£ +Perl ¤Ï¥µ¥Ö¥ë¡¼¥Á¥ó̾¤òÍç¤Îñ¸ì¤È¤·¤Æ½ñ¤¯¤³¤È¤òµö¤·¤Æ¤¤¤ë¤Î¤Ç¡¢ +¥á¥½¥Ã¥É¤Î¸å¤ÎÍç¤Îñ¸ì¤¬¥¯¥é¥¹Ì¾¤Ê¤Î¤«¥µ¥Ö¥ë¡¼¥Á¥ó̾¤Ê¤Î¤«¤ò +Perl ¤¬¿ä¬¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£ +¸À¤¤´¹¤¨¤ë¤È¡¢Perl ¤Ï¤³¤Îʸˡ¤ò C<< File->new( $path, $data ) >> +B<¤¢¤ë¤¤¤Ï> C<< new( File( $path, $data ) ) >> ¤È²ò¼á¤Ç¤¤Þ¤¹¡£ + +=begin original + +To parse this code, Perl uses a heuristic based on what package names +it has seen, what subroutines exist in the current package, what +barewords it has previously seen, and other input. Needless to say, +heuristics can produce very surprising results! + +=end original + +¤³¤Î¥³¡¼¥É¤ò¥Ñ¡¼¥¹¤¹¤ë¤¿¤á¤Ë¡¢ +Perl ¤Ï¤É¤ó¤Ê¥Ñ¥Ã¥±¡¼¥¸Ì¾¤¬¸«¤é¤ì¤ë¤«¡¢¤É¤ó¤Ê¥µ¥Ö¥ë¡¼¥Á¥ó¤¬¸½ºß¤Î +¥Ñ¥Ã¥±¡¼¥¸¤Ë¸ºß¤¹¤ë¤«¡¢¤É¤ó¤ÊÍç¤Îñ¸ì¤¬°ÊÁ°¤Ë¸«¤é¤ì¤¿¤«¡¢ +¤ª¤è¤Ó¤½¤Î¾¤ÎÆþÎϤò¸µ¤Ë¤·¤¿·Ð¸³Â§¤ò»È¤¤¤Þ¤¹¡£ +¸À¤¦¤Þ¤Ç¤â¤Ê¤¯¡¢·Ð¸³Â§¤Ï¤È¤Æ¤â¶Ã¤¯·ë²Ì¤ò¾·¤¯¤³¤È¤¬¤¢¤ê¤Þ¤¹! + +=begin original + +Older documentation (and some CPAN modules) encouraged this syntax, +particularly for constructors, so you may still find it in the wild. +However, we encourage you to avoid using it in new code. + +=end original + +¤è¤ê¸Å¤¤Ê¸½ñ (¤ª¤è¤Ó¤¤¤¯¤Ä¤«¤Î CPAN ¥â¥¸¥å¡¼¥ë) ¤Ç¤Ï¡¢ +Æä˥³¥ó¥¹¥È¥é¥¯¥¿¤Ë¤Ä¤¤¤Æ¡¢¤³¤Îʸˡ¤ò¿ä¾©¤·¤Æ¤¤¤¿¤Î¤Ç¡¢ +¤Þ¤ÀÀ¤¤ÎÃæ¤Ç¤³¤ì¤ò¸«¤ë¤³¤È¤¬¤¢¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¡£ +¤·¤«¤·¡¢¿·¤·¤¤¥³¡¼¥É¤Ë¤³¤ì¤ò»È¤¦¤³¤È¤ÏÈò¤±¤ë¤³¤È¤ò¿ä¾©¤·¤Þ¤¹¡£ + +=begin original + +You can force Perl to interpret the bareword as a class name by +appending "::" to it, like we saw earlier: + +=end original + +°ÊÁ°¤Ë¸«¤¿¤è¤¦¤Ë¡¢¥¯¥é¥¹Ì¾¤Ë "::" ¤òÉÕ¤±¤ë¤³¤È¤Ç¡¢Perl ¤¬Íç¤Îñ¸ì¤È¤·¤Æ +²ò¼á¤¹¤ë¤³¤È¤ò¶¯À©¤Ç¤¤Þ¤¹: + + my $file = new File:: $path, $data; + +=head2 C<bless>, C<blessed>, and C<ref> + +(C<bless>, C<blessed>, C<ref>) + +=begin original + +As we saw earlier, an object is simply a data structure that has been +blessed into a class via the C<bless> function. The C<bless> function +can take either one or two arguments: + +=end original + +´û¤Ë¸«¤¿¤è¤¦¤Ë¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Ï C<bless> ´Ø¿ô¤Ç¥¯¥é¥¹¤Ë bless ¤µ¤ì¤¿ +ñ¤Ê¤ë¥Ç¡¼¥¿¹½Â¤¤Ç¤¹¡£ +C<bless> ´Ø¿ô¤Ï°ì¤Ä¤Þ¤¿¤ÏÆó¤Ä¤Î°ú¿ô¤ò¼è¤ê¤Þ¤¹: + + my $object = bless {}, $class; + my $object = bless {}; + +=begin original + +In the first form, the anonymous hash is being blessed into the class +in C<$class>. In the second form, the anonymous hash is blessed into +the current package. + +=end original + +1 ÈÖÌܤηÁ¼°¤Ç¤Ï¡¢ÌµÌ¾¥Ï¥Ã¥·¥å¤Ï C<$class> ¤Î¥¯¥é¥¹¤Ë bless ¤µ¤ì¤Þ¤¹¡£ +2 ÈÖÌܤηÁ¼°¤Ç¤Ï¡¢ÌµÌ¾¥Ï¥Ã¥·¥å¤Ï¸½ºß¤Î¥Ñ¥Ã¥±¡¼¥¸¤Ë bless ¤µ¤ì¤Þ¤¹¡£ + +=begin original + +The second form is strongly discouraged, because it breaks the ability +of a subclass to reuse the parent's constructor, but you may still run +across it in existing code. + +=end original + +2 ÈÖÌܤηÁ¼°¤Ï¶¯¤¯Èó¿ä¾©¤Ç¤¹; ¤Ê¤¼¤Ê¤é¤³¤ì¤Ï¿Æ¤Î¥³¥ó¥¹¥È¥é¥¯¥¿¤ò +ºÆÍøÍѤ¹¤ë¥µ¥Ö¥¯¥é¥¹¤ÎǽÎϤò²õ¤¹¤«¤é¤Ç¤¹; +¤·¤«¤·´û¤Ë¸ºß¤·¤Æ¤¤¤ë¥³¡¼¥É¤Ç¤Ï¤Þ¤À¤³¤ì¤ò¸«¤ë¤³¤È¤¬¤¢¤ë¤Ç¤·¤ç¤¦¡£ + +=begin original + +If you want to know whether a particular scalar refers to an object, +you can use the C<blessed> function exported by L<Scalar::Util>, which +is shipped with the Perl core. + +=end original + +¤¢¤ë¥¹¥«¥é¤¬¥ª¥Ö¥¸¥§¥¯¥È¤ò»²¾È¤·¤Æ¤¤¤ë¤«¤É¤¦¤«¤òÃΤꤿ¤¤¾ì¹ç¡¢ +Perl ¥³¥¢¤ÈƱº¤µ¤ì¤Æ¤¤¤ë L<Scalar::Util> ¤«¤é¥¨¥¯¥¹¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë +C<blessed> ´Ø¿ô¤¬»È¤¨¤Þ¤¹¡£ + + use Scalar::Util 'blessed'; + + if ( defined blessed($thing) ) { ... } + +=begin original + +If C<$thing> refers to an object, then this function returns the name +of the package the object has been blessed into. If C<$thing> doesn't +contain a reference to a blessed object, the C<blessed> function +returns C<undef>. + +=end original + +C<$thing> ¤¬¥ª¥Ö¥¸¥§¥¯¥È¤ò»²¾È¤·¤Æ¤¤¤ë¤Ê¤é¡¢¤³¤Î´Ø¿ô¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤¬ +bless ¤µ¤ì¤Æ¤¤¤ë¥Ñ¥Ã¥±¡¼¥¸Ì¾¤òÊÖ¤·¤Þ¤¹¡£ +C<$thing> ¤¬ bless ¤µ¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò´Þ¤ó¤Ç¤¤¤Ê¤¤¤Ê¤é¡¢ +C<blessed> ´Ø¿ô¤Ï C<undef> ¤òÊÖ¤·¤Þ¤¹¡£ + +=begin original + +Note that C<blessed($thing)> will also return false if C<$thing> has +been blessed into a class named "0". This is a possible, but quite +pathological. Don't create a class named "0" unless you know what +you're doing. + +=end original + +will also return false +C<$thing> ¤¬ "0" ¤È¤¤¤¦Ì¾Á°¤Î¥¯¥é¥¹¤Ë bless ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤â +C<blessed($thing)> ¤Ïµ¶¤òÊÖ¤¹¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£ +¤³¤ì¤Ï²Äǽ¤Ç¤¹¤¬¡¢¤«¤Ê¤ê¶Ëü¤Ç¤¹¡£ +²¿¤ò¤·¤Æ¤¤¤ë¤«Ê¬¤«¤Ã¤Æ¤¤¤Ê¤¤¸Â¤ê¡¢"0" ¤È¤¤¤¦Ì¾Á°¤Î¥¯¥é¥¹¤ò +ºî¤é¤Ê¤¤¤Ç¤¯¤À¤µ¤¤¡£ + +=begin original + +Similarly, Perl's built-in C<ref> function treats a reference to a +blessed object specially. If you call C<ref($thing)> and C<$thing> +holds a reference to an object, it will return the name of the class +that the object has been blessed into. + +=end original + +ƱÍͤˡ¢Perl ¤ÎÁȤ߹þ¤ß¤Î C<ref> ´Ø¿ô¤Ï bless ¤µ¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î +¥ê¥Õ¥¡¥ì¥ó¥¹¤òÆÃÊ̤˰·¤¤¤Þ¤¹¡£ +C<ref($thing)> ¤ò¸Æ¤Ó½Ð¤·¤Æ¡¢C<$thing> ¤¬¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò +ÊÝ»ý¤·¤Æ¤¤¤ë¾ì¹ç¡¢¤³¤ì¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤¬ bless ¤µ¤ì¤Æ¤¤¤ë¥¯¥é¥¹Ì¾¤òÊÖ¤·¤Þ¤¹¡£ + +=begin original + +If you simply want to check that a variable contains an object +reference, we recommend that you use C<defined blessed($object)>, since +C<ref> returns true values for all references, not just objects. + +=end original + +ñ½ã¤Ë¤¢¤ëÊÑ¿ô¤¬¥ª¥Ö¥¸¥§¥¯¥È¥ê¥Õ¥¡¥ì¥ó¥¹¤ò´Þ¤ó¤Ç¤¤¤ë¤«¤ò¥Á¥§¥Ã¥¯¤·¤¿¤¤¾ì¹ç¡¢ +C<defined blessed($object)> ¤ò»È¤¦¤³¤È¤ò´«¤á¤Þ¤¹; +C<ref> ¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤À¤±¤Ç¤Ê¤¯Á´¤Æ¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤Ë´Ø¤·¤Æ¿¿¤ÎÃͤò +ÊÖ¤¹¤«¤é¤Ç¤¹¡£ + +=head2 The UNIVERSAL Class +X<UNIVERSAL> + +(UNIVERSAL ¥¯¥é¥¹) + +=begin original + +All classes automatically inherit from the L<UNIVERSAL> class, which is +built-in to the Perl core. This class provides a number of methods, all +of which can be called on either a class or an object. You can also +choose to override some of these methods in your class. If you do so, +we recommend that you follow the built-in semantics described below. + +=end original + +Á´¤Æ¤Î¥¯¥é¥¹¤Ï¡¢Perl ¥³¥¢¤ËÁȤ߹þ¤Þ¤ì¤Æ¤¤¤ë L<UNIVERSAL> ¥¯¥é¥¹¤«¤é +·Ñ¾µ¤µ¤ì¤Þ¤¹¡£ +¤³¤Î¥¯¥é¥¹¤Ï¡¢Á´¤Æ¥¯¥é¥¹¤Þ¤¿¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤«¤é¸Æ¤Ð¤ì¤ë +¤¤¤¯¤Ä¤«¤Î¥á¥½¥Ã¥É¤òÄ󶡤·¤Þ¤¹¡£ +¤Þ¤¿¡¢¼«¿È¤Î¥¯¥é¥¹¤Ç¤³¤ì¤é¤Î¥á¥½¥Ã¥É¤Î¤¤¤¯¤Ä¤«¤ò +¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë¤³¤È¤òÁª¤Ö¤³¤È¤â½ÐÍè¤Þ¤¹¡£ +¤½¤¦¤¹¤ë¾ì¹ç¤Ï¡¢¸å½Ò¤¹¤ëÁȤ߹þ¤ß¤Î°ÕÌ£ÏÀ¤Ë½¾¤¦¤³¤È¤ò´«¤á¤Þ¤¹¡£ + +=over 4 + +=item isa($class) +X<isa> + +=begin original + +The C<isa> method returns I<true> if the object is a member of the +class in C<$class>, or a member of a subclass of C<$class>. + +=end original + +C<isa> ¥á¥½¥Ã¥É¤Ï¡¢¥ª¥Ö¥¸¥§¥¯¥È¤¬ C<$class> ¤Î¥¯¥é¥¹¤«¡¢C<$class> ¤Î +¥µ¥Ö¥¯¥é¥¹¤Î¾ì¹ç¤Ë I<¿¿> ¤òÊÖ¤·¤Þ¤¹¡£ + +=begin original + +If you override this method, it should never throw an exception. + +=end original + +¤³¤Î¥á¥½¥Ã¥É¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë¾ì¹ç¡¢·è¤·¤ÆÎã³°¤òÅꤲ¤Ê¤¤¤è¤¦¤Ë +¤¹¤ë¤Ù¤¤Ç¤¹¡£ + +=item DOES($role) +X<DOES> + +=begin original + +The C<DOES> method returns I<true> if its object claims to perform the +role C<$role>. By default, this is equivalent to C<isa>. This method is +provided for use by object system extensions that implement roles, like +C<Moose> and C<Role::Tiny>. + +=end original + +C<DOES> ¥á¥½¥Ã¥É¤Ï¡¢¥ª¥Ö¥¸¥§¥¯¥È¤¬¥í¡¼¥ë C<$role> ¤ò¼Â¹Ô¤¹¤ë¤È¼çÄ¥¤·¤Æ¤¤¤ë +¾ì¹ç¤Ë I<¿¿> ¤òÊÖ¤·¤Þ¤¹¡£ +¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢¤³¤ì¤Ï C<isa> ¤ÈÅù²Á¤Ç¤¹¡£ +¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢C<Moose> and C<Role::Tiny> ¤Î¤è¤¦¤Ë¡¢¥í¡¼¥ë¤ò¼ÂÁõ¤·¤Æ¤¤¤ë +¥ª¥Ö¥¸¥§¥¯¥È¥·¥¹¥Æ¥à³ÈÄ¥¤Ë¤è¤Ã¤Æ»È¤ï¤ì¤ë¤¿¤á¤ËÄ󶡤µ¤ì¤Æ¤¤¤Þ¤¹¡£ + +=begin original + +You can also override C<DOES> directly in your own classes. If you +override this method, it should never throw an exception. + +=end original + +¤Þ¤¿¡¢¼«¿È¤Î¥¯¥é¥¹¤ÇľÀÜ C<DOES> ¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë¤³¤È¤â½ÐÍè¤Þ¤¹¡£ +¤³¤Î¥á¥½¥Ã¥É¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë¾ì¹ç¡¢·è¤·¤ÆÎã³°¤òÅꤲ¤Ê¤¤¤è¤¦¤Ë +¤¹¤ë¤Ù¤¤Ç¤¹¡£ + +=item can($method) +X<can> + +=begin original + +The C<can> method checks to see if the class or object it was called on +has a method named C<$method>. This checks for the method in the class +and all of its parents. If the method exists, then a reference to the +subroutine is returned. If it does not then C<undef> is returned. + +=end original + +C<can> ¥á¥½¥Ã¥É¤Ï¡¢¸Æ¤Ó½Ð¤µ¤ì¤¿¥¯¥é¥¹¤Þ¤¿¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤¬ +C<$method> ¤È¤¤¤¦Ì¾Á°¤Î¥á¥½¥Ã¥É¤ò»ý¤Ã¤Æ¤¤¤ë¤«¤ò¥Á¥§¥Ã¥¯¤·¤Þ¤¹¡£ +¤³¤ì¤Ï¤½¤Î¥¯¥é¥¹¤ª¤è¤ÓÁ´¤Æ¤Î¿Æ¤Î¥á¥½¥Ã¥É¤ò¥Á¥§¥Ã¥¯¤·¤Þ¤¹¡£ +¥á¥½¥Ã¥É¤¬Â¸ºß¤¹¤ë¾ì¹ç¡¢¥µ¥Ö¥ë¡¼¥Á¥ó¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤òÊÖ¤·¤Þ¤¹¡£ +¸ºß¤·¤Ê¤±¤ì¤Ð C<undef> ¤¬ÊÖ¤µ¤ì¤Þ¤¹¡£ + +=begin original + +If your class responds to method calls via C<AUTOLOAD>, you may want to +overload C<can> to return a subroutine reference for methods which your +C<AUTOLOAD> method handles. + +=end original + +¤¢¤Ê¤¿¤Î¥¯¥é¥¹¤¬ C<AUTOLOAD> ·Ðͳ¤Î¥á¥½¥Ã¥É¸Æ¤Ó½Ð¤·¤ËÂбþ¤¹¤ë¾ì¹ç¡¢ +C<AUTOLOAD> ¥á¥½¥Ã¥É¤¬°·¤¦¥á¥½¥Ã¥É¤Ë¤Ä¤¤¤Æ¥µ¥Ö¥ë¡¼¥Á¥ó¥ê¥Õ¥¡¥ì¥ó¥¹¤ò +ÊÖ¤¹¤è¤¦¤Ë C<can> ¤ò¥ª¡¼¥Ð¡¼¥í¡¼¥É¤·¤¿Êý¤¬Îɤ¤¤Ç¤·¤ç¤¦¡£ + +=begin original + +If you override this method, it should never throw an exception. + +=end original + +¤³¤Î¥á¥½¥Ã¥É¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë¾ì¹ç¡¢·è¤·¤ÆÎã³°¤òÅꤲ¤Ê¤¤¤è¤¦¤Ë +¤¹¤ë¤Ù¤¤Ç¤¹¡£ + +=item VERSION($need) +X<VERSION> + +=begin original + +The C<VERSION> method returns the version number of the class +(package). + +=end original + +C<VERSION> ¥á¥½¥Ã¥É¤Ï¥¯¥é¥¹ (¥Ñ¥Ã¥±¡¼¥¸) ¤Î¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤òÊÖ¤·¤Þ¤¹¡£ + +=begin original + +If the C<$need> argument is given then it will check that the current +version (as defined by the $VERSION variable in the package) is greater +than or equal to C<$need>; it will die if this is not the case. This +method is called automatically by the C<VERSION> form of C<use>. + +=end original + +C<$need> °ú¿ô¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢¸½ºß¤Î¥Ð¡¼¥¸¥ç¥ó (¥Ñ¥Ã¥±¡¼¥¸¤Î +$VERSION ÊÑ¿ô¤Ë¤è¤Ã¤ÆÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤â¤Î) ¤¬ C<$need> °Ê¾å¤«¤É¤¦¤«¤ò +¥Á¥§¥Ã¥¯¤·¤Þ¤¹; ¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¤Ï die ¤·¤Þ¤¹¡£ +¤³¤Î¥á¥½¥Ã¥É¤Ï C<use> ¤Î C<VERSION> ·Á¼°¤Ë¤è¤Ã¤Æ¼«Æ°Åª¤Ë¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£ + + use Package 1.2 qw(some imported subs); + # implies: + Package->VERSION(1.2); + +=begin original + +We recommend that you use this method to access another package's +version, rather than looking directly at C<$Package::VERSION>. The +package you are looking at could have overridden the C<VERSION> method. + +=end original + +¾¤Î¥Ñ¥Ã¥±¡¼¥¸¤Î¥Ð¡¼¥¸¥ç¥ó¤Ë¥¢¥¯¥»¥¹¤¹¤ë¾ì¹ç¤Ï¡¢Ä¾ÀÜ +C<$Package::VERSION> ¤ò¸«¤ë¤Î¤Ç¤Ï¤Ê¤¯¤³¤Î¥á¥½¥Ã¥É¤ò»È¤¦¤³¤È¤ò´«¤á¤Þ¤¹¡£ +¸«¤è¤¦¤È¤·¤Æ¤¤¤ë¥Ñ¥Ã¥±¡¼¥¸¤Ï C<VERSION> ¥á¥½¥Ã¥É¤ò +¥ª¡¼¥Ð¡¼¥é¥¤¥É¤·¤Æ¤¤¤ë¤«¤âÃΤì¤Þ¤»¤ó¡£ + +=begin original + +We also recommend using this method to check whether a module has a +sufficient version. The internal implementation uses the L<version> +module to make sure that different types of version numbers are +compared correctly. + +=end original + +¤Þ¤¿¡¢¤¢¤ë¥â¥¸¥å¡¼¥ë¤Î¥Ð¡¼¥¸¥ç¥ó¤¬½½Ê¬¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¤¹¤ë¤Î¤Ë +¤³¤Î¥á¥½¥Ã¥É¤ò»È¤¦¤³¤È¤ò´«¤á¤Þ¤¹¡£ +ÆâÉô¼ÂÁõ¤Ï¡¢°Û¤Ê¤Ã¤¿¼ïÎà¤Î¥Ð¡¼¥¸¥ç¥óÈֹ椬Àµ¤·¤¯Èæ³Ó¤µ¤ì¤ë¤è¤¦¤Ë +L<version> ¥â¥¸¥å¡¼¥ë¤ò»È¤¤¤Þ¤¹¡£ + +=back + +=head2 AUTOLOAD +X<AUTOLOAD> + +=begin original + +If you call a method that doesn't exist in a class, Perl will throw an +error. However, if that class or any of its parent classes defines an +C<AUTOLOAD> method, that C<AUTOLOAD> method is called instead. + +=end original + +¥¯¥é¥¹¤Ë¸ºß¤·¤Ê¤¤¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹¤È¡¢Perl ¤ÏÎã³°¤òÅꤲ¤Þ¤¹¡£ +¤·¤«¤·¡¢¤½¤Î¥¯¥é¥¹¤Þ¤¿¤Ï¿Æ¥¯¥é¥¹¤Ë +C<AUTOLOAD> ¥á¥½¥Ã¥É¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤È¡¢Âå¤ï¤ê¤Ë C<AUTOLOAD> ¥á¥½¥Ã¥É¤¬ +¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£ + +=begin original + +C<AUTOLOAD> is called as a regular method, and the caller will not know +the difference. Whatever value your C<AUTOLOAD> method returns is +returned to the caller. + +=end original + +C<AUTOLOAD> ¤ÏÄ̾ï¤Î¥á¥½¥Ã¥É¤È¤·¤Æ¸Æ¤Ó½Ð¤µ¤ì¡¢¸Æ¤Ó½Ð¤·¸µ¤Ï +°ã¤¤¤òÃΤ뤳¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£ +the difference. Whatever value your +C<AUTOLOAD> ¥á¥½¥Ã¥É¤¬ÊÖ¤·¤¿Ãͤ¬¸Æ¤Ó½Ð¤·¸µ¤ËÊÖ¤µ¤ì¤Þ¤¹¡£ + +=begin original + +The fully qualified method name that was called is available in the +C<$AUTOLOAD> package global for your class. Since this is a global, if +you want to refer to do it without a package name prefix under C<strict +'vars'>, you need to declare it. + +=end original + +¸Æ¤Ó½Ð¤µ¤ì¤¿´°Á´½¤¾þ¥á¥½¥Ã¥É̾¤Ï¤¢¤Ê¤¿¤Î¥¯¥é¥¹¤Î¥Ñ¥Ã¥±¡¼¥¸¥°¥í¡¼¥Ð¥ëÊÑ¿ô +C<$AUTOLOAD> ¤«¤éÍøÍѲÄǽ¤Ç¤¹¡£ +¤³¤ì¤Ï¥°¥í¡¼¥Ð¥ë¤Ê¤Î¤Ç¡¢ +C<strict 'vars'> ¤Î´ð¤Ç¥Ñ¥Ã¥±¡¼¥¸Ì¾ÀÜƬ¼¤Ê¤·¤Ç¤³¤ì¤ò»²¾È¤·¤¿¤¤¾ì¹ç¤Ï¡¢ +Àë¸À¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£ + + # XXX - this is a terrible way to implement accessors, but it makes + # for a simple example. + our $AUTOLOAD; + sub AUTOLOAD { + my $self = shift; + + # Remove qualifier from original method name... + my $called = $AUTOLOAD =~ s/.*:://r; + + # Is there an attribute of that name? + die "No such attribute: $called" + unless exists $self->{$called}; + + # If so, return it... + return $self->{$called}; + } + + sub DESTROY { } # see below + +=begin original + +Without the C<our $AUTOLOAD> declaration, this code will not compile +under the L<strict> pragma. + +=end original + +C<our $AUTOLOAD> Àë¸À¤Ê¤·¤À¤È¡¢¤³¤Î¥³¡¼¥É¤Ï +L<strict> ¥×¥é¥°¥Þ¤Î´ð¤Ç¤Ï¥³¥ó¥Ñ¥¤¥ë½ÐÍè¤Þ¤»¤ó¡£ + +=begin original + +As the comment says, this is not a good way to implement accessors. +It's slow and too clever by far. However, you may see this as a way to +provide accessors in older Perl code. See L<perlootut> for +recommendations on OO coding in Perl. + +=end original + +¥³¥á¥ó¥È¤Ë¤¢¤ë¤è¤¦¤Ë¡¢¤³¤ì¤Ï¥¢¥¯¥»¥µ¤ò¼ÂÁõ¤¹¤ë¤¿¤á¤ÎÎɤ¤ÊýË¡¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£ +¤³¤ì¤ÏÃÙ¤¯¡¢¤Ï¤ë¤«¤Ë¸¤¹¤®¤Þ¤¹¡£ +¤·¤«¤·¡¢¸Å¤¤ Perl ¥³¡¼¥É¤Ç¥¢¥¯¥»¥µ¤òÄ󶡤¹¤ëÊýË¡¤È¤·¤Æ¤³¤ì¤ò +¸«¤ë¤³¤È¤¬¤¢¤ë¤«¤âÃΤì¤Þ¤»¤ó¡£ +Perl ¤Ç¤Î OO ¥³¡¼¥Ç¥£¥ó¥°¤Î¿ä¾©¤Ë¤Ä¤¤¤Æ¤Ï L<perlootut> ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=begin original + +If your class does have an C<AUTOLOAD> method, we strongly recommend +that you override C<can> in your class as well. Your overridden C<can> +method should return a subroutine reference for any method that your +C<AUTOLOAD> responds to. + +=end original + +¥¯¥é¥¹¤Ë C<AUTOLOAD> ¥á¥½¥Ã¥É¤¬¤¢¤ë¾ì¹ç¡¢ +C<can> ¤â¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë¤³¤È¤ò¶¯¤¯´«¤á¤Þ¤¹¡£ +¥ª¡¼¥Ð¡¼¥é¥¤¥É¤µ¤ì¤¿ C<can> ¥á¥½¥Ã¥É¤Ï¡¢C<AUTOLOAD> ¤¬Âбþ¤¹¤ë +¥á¥½¥Ã¥É¤Ë¤Ä¤¤¤Æ¥µ¥Ö¥ë¡¼¥Á¥ó¥ê¥Õ¥¡¥ì¥ó¥¹¤òÊÖ¤¹¤Ù¤¤Ç¤¹¡£ + +=head2 Destructors +X<destructor> X<DESTROY> + +(¥Ç¥¹¥È¥é¥¯¥¿) + +=begin original + +When the last reference to an object goes away, the object is +destroyed. If you only have one reference to an object stored in a +lexical scalar, the object is destroyed when that scalar goes out of +scope. If you store the object in a package global, that object may not +go out of scope until the program exits. + +=end original + +¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤ÎºÇ¸å¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤¬¤Ê¤¯¤Ê¤ë¤È¡¢¥ª¥Ö¥¸¥§¥¯¥È¤ÏÇ˲õ¤µ¤ì¤Þ¤¹¡£ +¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î°ì¤Ä¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò¥ì¥¥·¥«¥ë¤Ê¥¹¥«¥é¤ËÆþ¤ì¤Æ¤¤¤ë¤À¤±¤Î +¾ì¹ç¡¢¥¹¥«¥é¤¬¥¹¥³¡¼¥×³°¤Ë½Ð¤ë¤È¥ª¥Ö¥¸¥§¥¯¥È¤ÏÇ˲õ¤µ¤ì¤Þ¤¹¡£ +¥ª¥Ö¥¸¥§¥¯¥È¤ò¥Ñ¥Ã¥±¡¼¥¸¥°¥í¡¼¥Ð¥ë¤ËÊݴɤ¹¤ë¤È¡¢¥×¥í¥°¥é¥à¤¬½ªÎ»¤¹¤ë¤Þ¤Ç +¥ª¥Ö¥¸¥§¥¯¥È¤Ï¤Ê¤¯¤Ê¤é¤Ê¤¤¤«¤â¤·¤ì¤Þ¤»¤ó¡£ + +=begin original + +If you want to do something when the object is destroyed, you can +define a C<DESTROY> method in your class. This method will always be +called by Perl at the appropriate time, unless the method is empty. + +=end original + +¥ª¥Ö¥¸¥§¥¯¥È¤¬Ç˲õ¤µ¤ì¤ë¤È¤¤Ë²¿¤«¤ò¤·¤¿¤¤¾ì¹ç¡¢ +¼«Ê¬¤Î¥¯¥é¥¹¤Ë C<DESTROY> ¥á¥½¥Ã¥É¤òÄêµÁ¤Ç¤¤Þ¤¹¡£ +¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢¶õ¤Ç¤Ê¤¤¸Â¤ê¡¢Å¬ÀڤʻþÅÀ¤Ç¾ï¤Ë Perl ¤Ë¤è¤Ã¤Æ¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£ + +=begin original + +This is called just like any other method, with the object as the first +argument. It does not receive any additional arguments. However, the +C<$_[0]> variable will be read-only in the destructor, so you cannot +assign a value to it. + +=end original + +¤³¤ì¤Ï¡¢Â¾¤Î¥á¥½¥Ã¥É¤ÈƱÍÍ¡¢¥ª¥Ö¥¸¥§¥¯¥È¤òºÇ½é¤Î°ú¿ô¤È¤·¤Æ¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£ +¤³¤ì¤ÏÄɲäΰú¿ô¤Ï¼õ¤±¼è¤ê¤Þ¤»¤ó¡£ +¤·¤«¤·¡¢C<$_[0]> ÊÑ¿ô¤Ï¥Ç¥¹¥È¥é¥¯¥¿¤ÎÃæ¤Ç¤ÏÆɤ߹þ¤ßÀìÍѤʤΤǡ¢ +¤³¤ì¤ËÃͤòÂåÆþ¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£ + +=begin original + +If your C<DESTROY> method throws an error, this error will be ignored. +It will not be sent to C<STDERR> and it will not cause the program to +die. However, if your destructor is running inside an C<eval {}> block, +then the error will change the value of C<$@>. + +=end original + +C<DESTROY> ¥á¥½¥Ã¥É¤¬¥¨¥é¡¼¤òÅꤲ¤¿¾ì¹ç¡¢¤³¤Î¥¨¥é¡¼¤Ï̵»ë¤µ¤ì¤Þ¤¹¡£ +¤³¤ì¤Ï C<STDERR> ¤ËÁ÷¤é¤ì¤º¡¢¥×¥í¥°¥é¥à¤Î die ¤ò°ú¤µ¯¤³¤·¤Þ¤»¤ó¡£ +¤·¤«¤·¡¢¥Ç¥¹¥È¥é¥¯¥¿¤¬ C<eval {}> ¥Ö¥í¥Ã¥¯¤ÎÃæ¤Ç¼Â¹Ô¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢ +¥¨¥é¡¼¤Ï C<$@> ¤ÎÃͤòÊѹ¹¤·¤Þ¤¹¡£ + +=begin original + +Because C<DESTROY> methods can be called at any time, you should +localize any global variables you might update in your C<DESTROY>. In +particular, if you use C<eval {}> you should localize C<$@>, and if you +use C<system> or backticks, you should localize C<$?>. + +=end original + +C<DESTROY> ¥á¥½¥Ã¥É¤Ï¤¢¤é¤æ¤ë»þÅÀ¤Ç¸Æ¤Ó½Ð¤µ¤ì¤ë²ÄǽÀ¤¬¤¢¤ë¤Î¤Ç¡¢ +C<DESTROY> ¤ÎÃæ¤Ç¹¹¿·¤µ¤ì¤ë¤«¤âÃΤì¤Ê¤¤Á´¤Æ¤Î¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤ò +¥í¡¼¥«¥ë²½¤¹¤ë¤Ù¤¤Ç¤¹¡£ +Æäˡ¢C<eval {}> ¤ò»È¤¦¾ì¹ç¤Ï C<$@> ¤ò¥í¡¼¥«¥ë²½¤¹¤ë¤Ù¤¤Ç¡¢ +C<system> ¤äµÕ¥¯¥©¡¼¥È¤ò»È¤¦¾ì¹ç¤Ï C<$?> ¤ò¥í¡¼¥«¥ë²½¤¹¤ë¤Ù¤¤Ç¤¹¡£ + +=begin original + +If you define an C<AUTOLOAD> in your class, then Perl will call your +C<AUTOLOAD> to handle the C<DESTROY> method. You can prevent this by +defining an empty C<DESTROY>, like we did in the autoloading example. +You can also check the value of C<$AUTOLOAD> and return without doing +anything when called to handle C<DESTROY>. + +=end original + +¥¯¥é¥¹Æâ¤Ç C<AUTOLOAD> ¤òÄêµÁ¤·¤Æ¤¤¤ë¾ì¹ç¡¢ +Perl ¤Ï C<DESTROY> ¥á¥½¥Ã¥É¤ò°·¤¦¤¿¤á¤Ë C<AUTOLOAD> ¤ò¸Æ¤Ó½Ð¤·¤Þ¤¹¡£ +¥ª¡¼¥È¥í¡¼¥É¤ÎÎã¤Ç¹Ô¤Ã¤¿¤è¤¦¤Ë¡¢¶õ¤Î C<DESTROY> ¤òÄêµÁ¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ +¤³¤ì¤òËɤ²¤Þ¤¹¡£ +¤Þ¤¿¡¢C<$AUTOLOAD> ¤ÎÃͤò¥Á¥§¥Ã¥¯¤·¤Æ¡¢C<DESTROY> ¤ò°·¤¦¤¿¤á¤Ë +¸Æ¤Ó½Ð¤µ¤ì¤¿¤È¤¤Ë¤Ï²¿¤â¤»¤º¤ËÊ֤뤳¤È¤â¤Ç¤¤Þ¤¹¡£ + +=head3 Global Destruction + +(¥°¥í¡¼¥Ð¥ë¤ÊÇ˲õ) + +=begin original + +The order in which objects are destroyed during the global destruction +before the program exits is unpredictable. This means that any objects +contained by your object may already have been destroyed. You should +check that a contained object is defined before calling a method on it: + +=end original + +¥×¥í¥°¥é¥à¤¬½ªÎ»¤¹¤ëÁ°¤Î¥°¥í¡¼¥Ð¥ë¤ÊÇ˲õ¤Î´Ö¤Ë¥ª¥Ö¥¸¥§¥¯¥È¤¬Ç˲õ¤µ¤ì¤ë +½ç½ø¤Ïͽ¬¤Ç¤¤Þ¤»¤ó¡£ +¤Ä¤Þ¤ê¡¢¤¢¤Ê¤¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ï´û¤Ë +Ç˲õ¤µ¤ì¤Æ¤¤¤ë¤«¤âÃΤì¤Ê¤¤¤È¤¤¤¦¤³¤È¤Ç¤¹¡£ +´Þ¤Þ¤ì¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¤ò¸Æ¤Ó½Ð¤¹Á°¤Ë¤½¤Î¥á¥½¥Ã¥É¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤ò +¥Á¥§¥Ã¥¯¤¹¤ë¤Ù¤¤Ç¤¹: + + sub DESTROY { + my $self = shift; + + $self->{handle}->close() if $self->{handle}; + } + +=begin original + +You can use the C<${^GLOBAL_PHASE}> variable to detect if you are +currently in the global destruction phase: + +=end original + +¸½ºß¥°¥í¡¼¥Ð¥ëÇ˲õ¥Õ¥§¡¼¥ºÃæ¤Ê¤Î¤«¤ò¸¡½Ð¤¹¤ë¤¿¤á¤Ë¡¢ +C<${^GLOBAL_PHASE}> ÊÑ¿ô¤¬»È¤¨¤Þ¤¹: + + sub DESTROY { + my $self = shift; + + return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; + + $self->{handle}->close(); + } + +=begin original + +Note that this variable was added in Perl 5.14.0. If you want to detect +the global destruction phase on older versions of Perl, you can use the +C<Devel::GlobalDestruction> module on CPAN. + +=end original + +¤³¤ÎÊÑ¿ô¤Ï Perl 5.14.0 ¤ÇÄɲ䵤줿¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£ +¤è¤ê¸Å¤¤¥Ð¡¼¥¸¥ç¥ó¤Î Perl ¤Ç¥°¥í¡¼¥Ð¥ëÇ˲õ¥Õ¥§¡¼¥º¤ò¸¡½Ð¤·¤¿¤¤¾ì¹ç¤Ï¡¢ +CPAN ¤Î C<Devel::GlobalDestruction> ¥â¥¸¥å¡¼¥ë¤ò»È¤¨¤Þ¤¹¡£ + +=begin original + +If your C<DESTROY> method issues a warning during global destruction, +the Perl interpreter will append the string " during global +destruction" the warning. + +=end original + +C<DESTROY> ¥á¥½¥Ã¥É¤¬¥°¥í¡¼¥Ð¥ë¤ÊÇ˲õÃæ¤Ë·Ù¹ð¤ò½Ð¤·¤¿¾ì¹ç¡¢ +Perl ¥¤¥ó¥¿¥×¥ê¥¿¤Ï·Ù¹ð¤Ë " during global destruction" ¤È¤¤¤¦Ê¸»úÎó¤ò +Äɲä·¤Þ¤¹¡£ + +=begin original + +During global destruction, Perl will always garbage collect objects +before unblessed references. See L<perlhacktips/PERL_DESTRUCT_LEVEL> +for more information about global destruction. + +=end original + +¥°¥í¡¼¥Ð¥ë¤ÊÇ˲õ¤Î´Ö¡¢Perl ¤Ï¾ï¤Ë¥ê¥Õ¥¡¥ì¥ó¥¹¤Î bless ²ò½ü¤ÎÁ°¤Ë +¥ª¥Ö¥¸¥§¥¯¥È¤ò¥¬¥Ù¡¼¥¸¥³¥ì¥¯¥·¥ç¥ó¤·¤Þ¤¹¡£ +¥°¥í¡¼¥Ð¥ë¤ÊÇ˲õ¤Ë´Ø¤¹¤ë¤µ¤é¤Ê¤ë¾ðÊó¤Ë¤Ä¤¤¤Æ¤Ï +L<perlhacktips/PERL_DESTRUCT_LEVEL> ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=head2 Non-Hash Objects + +(Èó¥Ï¥Ã¥·¥å¥ª¥Ö¥¸¥§¥¯¥È) + +=begin original + +All the examples so far have shown objects based on a blessed hash. +However, it's possible to bless any type of data structure or referent, +including scalars, globs, and subroutines. You may see this sort of +thing when looking at code in the wild. + +=end original + +º£¤Þ¤Ç¤ÎÁ´¤Æ¤ÎÎã¤Ç¤Ï¥ª¥Ö¥¸¥§¥¯¥È¤Ï bless ¤µ¤ì¤¿¥Ï¥Ã¥·¥å¤ò´ð¤Ë¤·¤Æ¤¤¤Þ¤·¤¿¡£ +¤·¤«¤·¡¢¥¹¥«¥é¡¢¥°¥í¥Ö¡¢¥µ¥Ö¥ë¡¼¥Á¥ó¤ò´Þ¤à¤¢¤é¤æ¤ë¼ïÎà¤Î¥Ç¡¼¥¿¹½Â¤¤ä +»²¾ÈÀè¤ò bless ¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£ +À¤¤ÎÃæ¤Î¥³¡¼¥É¤ò¸«¤¿¤È¤¤Ë¤½¤Î¤è¤¦¤Ê¤â¤Î¤ò¸«¤ë¤«¤âÃΤì¤Þ¤»¤ó¡£ + +=begin original + +Here's an example of a module as a blessed scalar: + +=end original + +¤³¤ì¤Ï bless ¤µ¤ì¤¿¥¹¥«¥é¤È¤·¤Æ¤Î¥â¥¸¥å¡¼¥ë¤ÎÎã¤Ç¤¹: + + package Time; + + use strict; + use warnings; + + sub new { + my $class = shift; + + my $time = time; + return bless \$time, $class; + } + + sub epoch { + my $self = shift; + return ${ $self }; + } + + my $time = Time->new(); + print $time->epoch(); + +=head2 Inside-Out objects + +(¥¤¥ó¥µ¥¤¥É¥¢¥¦¥È¥ª¥Ö¥¸¥§¥¯¥È) + +=begin original + +In the past, the Perl community experimented with a technique called +"inside-out objects". An inside-out object stores its data outside of +the object's reference, indexed on a unique property of the object, +such as its memory address, rather than in the object itself. This has +the advantage of enforcing the encapsulation of object attributes, +since their data is not stored in the object itself. + +=end original + +²áµî¤Ë¡¢Perl ¥³¥ß¥å¥Ë¥Æ¥£¤Ï¡Ö¥¤¥ó¥µ¥¤¥É¥¢¥¦¥È¥ª¥Ö¥¸¥§¥¯¥È¡×¤È¸Æ¤Ð¤ì¤ë +¥Æ¥¯¥Ë¥Ã¥¯¤ò¼Â¸³¤·¤Þ¤·¤¿¡£ +¥¤¥ó¥µ¥¤¥É¥¢¥¦¥È¥ª¥Ö¥¸¥§¥¯¥È¤Ï¡¢¤½¤Î¥Ç¡¼¥¿¤ò¥ª¥Ö¥¸¥§¥¯¥È¼«¿È¤Ç¤Ï¤Ê¤¯¡¢ +¤½¤Î¥á¥â¥ê¥¢¥É¥ì¥¹¤Î¤è¤¦¤Ê¥ª¥Ö¥¸¥§¥¯¥È¤Î¥æ¥Ë¡¼¥¯¤Ê°À¤ò¥¤¥ó¥Ç¥Ã¥¯¥¹¤È¤·¤Æ¡¢ +¥ª¥Ö¥¸¥§¥¯¥È¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤Î³°Â¦¤ËÊݴɤ·¤Þ¤¹¡£ +¤³¤ì¤Ï¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Î°À¤Î¥«¥×¥»¥ë²½¤ò¶¯À©¤¹¤ë¤È¤¤¤¦ÍøÅÀ¤¬¤¢¤ê¤Þ¤¹; +¤Ê¤¼¤Ê¤é¤½¤ì¤é¤Î¥Ç¡¼¥¿¤Ï¥ª¥Ö¥¸¥§¥¯¥È¼«¿È¤ËÊݴɤµ¤ì¤Ê¤¤¤«¤é¤Ç¤¹¡£ + +=begin original + +This technique was popular for a while (and was recommended in Damian +Conway's I<Perl Best Practices>), but never achieved universal +adoption. The L<Object::InsideOut> module on CPAN provides a +comprehensive implementation of this technique, and you may see it or +other inside-out modules in the wild. + +=end original + +¤³¤Î¥Æ¥¯¥Ë¥Ã¥¯¤Ï¤·¤Ð¤é¤¯¤Î´Ö¿Íµ¤¤¬¤¢¤ê +(¤½¤·¤Æ Damian Conway ¤Î I<Perl Best Practices> ¤Ç¿ä¾©¤µ¤ì) ¤Þ¤·¤¿¤¬¡¢ +°ìÈÌŪ¤ÊºÎÍѤòãÀ®¤¹¤ë¤³¤È¤Ï¤¢¤ê¤Þ¤»¤ó¤Ç¤·¤¿¡£ +CPAN ¤Î L<Object::InsideOut> ¥â¥¸¥å¡¼¥ë¤Ï¤³¤Î¥Æ¥¯¥Ë¥Ã¥¯¤ÎÊñ³çŪ¤Ê +¼ÂÁõ¤òÄ󶡤·¡¢À¤¤ÎÃæ¤Ç¤Ï¤³¤ì¤ä¤½¤Î¾¤Î¥¤¥ó¥µ¥¤¥É¥¢¥¦¥È¥â¥¸¥å¡¼¥ë¤ò +¸«¤«¤±¤ë¤«¤âÃΤì¤Þ¤»¤ó¡£ + +=begin original + +Here is a simple example of the technique, using the +L<Hash::Util::FieldHash> core module. This module was added to the core +to support inside-out object implementations. + +=end original + +¤³¤ì¤Ï L<Hash::Util::FieldHash> ¥³¥¢¥â¥¸¥å¡¼¥ë¤ò»È¤Ã¤¿¤³¤Î¥Æ¥¯¥Ë¥Ã¥¯¤Î +´Êñ¤ÊÎã¤Ç¤¹¡£ +¤³¤Î¥â¥¸¥å¡¼¥ë¤Ï¥¤¥ó¥µ¥¤¥É¥¢¥¦¥È¥ª¥Ö¥¸¥§¥¯¥È¼ÂÁõ¤ËÂбþ¤¹¤ë¤¿¤á¤Ë +¥³¥¢¤ËÄɲ䵤ì¤Þ¤·¤¿¡£ + + package Time; + + use strict; + use warnings; + + use Hash::Util::FieldHash 'fieldhash'; + + fieldhash my %time_for; + + sub new { + my $class = shift; + + my $self = bless \( my $object ), $class; + + $time_for{$self} = time; + + return $self; + } + + sub epoch { + my $self = shift; + + return $time_for{$self}; + } + + my $time = Time->new; + print $time->epoch; + +=head2 Pseudo-hashes + +(µ¿»÷¥Ï¥Ã¥·¥å) + +=begin original + +The pseudo-hash feature was an experimental feature introduced in +earlier versions of Perl and removed in 5.10.0. A pseudo-hash is an +array reference which can be accessed using named keys like a hash. You +may run in to some code in the wild which uses it. See the L<fields> +pragma for more information. + +=end original + +µ¿»÷¥Ï¥Ã¥·¥åµ¡Ç½¤Ï¡¢°ÊÁ°¤Î¥Ð¡¼¥¸¥ç¥ó¤Î Perl ¤ÇƳÆþ¤µ¤ì¡¢ +5.10.0 ¤Çºï½ü¤µ¤ì¤¿¼Â¸³Åªµ¡Ç½¤Ç¤¹¡£ +µ¿»÷¥Ï¥Ã¥·¥å¤Ï¡¢¥Ï¥Ã¥·¥å¤Î¤è¤¦¤Ë̾Á°ÉÕ¤¤Î¥¡¼¤ò»È¤Ã¤Æ¥¢¥¯¥»¥¹¤µ¤ì¤ë +ÇÛÎó¥ê¥Õ¥¡¥ì¥ó¥¹¤Ç¤¹¡£ +¤³¤ì¤ò»È¤Ã¤¿¥³¡¼¥É¤Ë½Ð¤¯¤ï¤¹¤³¤È¤¬¤¢¤ë¤«¤âÃΤì¤Þ¤»¤ó¡£ +¤µ¤é¤Ê¤ë¾ðÊó¤Ë¤Ä¤¤¤Æ¤Ï L<fields> ¥×¥é¥°¥Þ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=head1 SEE ALSO + +=begin original + +A kinder, gentler tutorial on object-oriented programming in Perl can +be found in L<perlootut>. You should also check out L<perlmodlib> for +some style guides on constructing both modules and classes. + +=end original + +Perl ¤Ç¤Î¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ¥×¥í¥°¥é¥ß¥ó¥°¤Ë´Ø¤¹¤ë¤è¤ê¿ÆÀÚ¤ÇÍ¥¤·¤¤ +¥Á¥å¡¼¥È¥ê¥¢¥ë¤Ï L<perlootut> ¤Ë¤¢¤ê¤Þ¤¹¡£ +¤Þ¤¿¡¢¥â¥¸¥å¡¼¥ë¤È¥¯¥é¥¹¤ÎξÊý¤ò¹½ÃÛ¤¹¤ë¤¿¤á¤Î¥¹¥¿¥¤¥ë¥¬¥¤¥É¤Ë¤Ä¤¤¤Æ +L<perlmodlib> ¤ò¥Á¥§¥Ã¥¯¤¹¤ë¤Ù¤¤Ç¤¹¡£ + +=begin meta + +Translate: SHIRAKATA Kentaro <argra****@ub32*****> +Status: completed + +=end meta +