2009年6月21日星期日

Object Oriented Perl

除非指定全称(例如 $SomePackage::SomeVar),否则在其他Package内无法访问当前Package的包变量

local只对包变量起作用,示例见图2.5

图2.6 符号表(Symbol Table)中的一个类型团(TypeGlob)

一些间接调用例子:

$funcname = "example";

&{"SomePackage::".$funcname}();  #相当于 SomePackage::example();

$symref = "set";

$symref->{type} =  "test";   #相当于 $set{type} = "test";

$symref->("data");  #相当于 set("data");

${"somevar"}相当于$main::somevar

bless 绑定一个变量到一个指定的类。

用{}防止外界存取本地变量,例如:

package CD::Music;
{
my $_count = 0;
sub get_count { $_count }
my $_incr_count  = sub { ++$_count };
sub new
{
$_incr_count->();
# etc. as before
}
# Other methods that need to adjust the 
# count value, via $_incr_count, go here
}
# Methods that don't need to adjust
# the count value go here

3.3.3 Reducing the cost of autoloading

3.4.1 A separate clone method

图3.4及图3.5 循环引用需自定义DESTROY函数,先解引用后再自动销毁变量

4.2.1 An array-specific example-iterators

use fields qw( receive transmit );

my Classname ($variable_name1, $variable_name2, $etc);

Chapter 5 Blessing other things

6.1.3 Where the call goes 类函数调用过程

6.2 TRICKS AND TRAPS 有一些容易出错的情况说明,比如继承时调用的基类函数

辅助类开发:Class::Struct,Class::Method::Maker,Class::Multimethods

一些模块:Storable,FreezeThaw,Storage,DB_FILE

Chapter 9 Ties

没有评论:

发表评论