0

这个想法是实现一个类,该类在 TIEHASH 构造函数中获取 [arrays, Thread::Conveyor queues and other stuff] 列表,

use AbstractHash; 
tie(%DATA, 'AbstractHash', \@a1, \@a2, \$tcq);

将对象引用(如提到的Thread::Conveyor对象)从而将数组引用传递给构造函数的正确方法是什么,以便它可以访问对象?传递的对象应该被祝福的任何情况?

4

1 回答 1

1

据我所知,对象不是对象,除非它们是bless-ed。

也就是说,构造函数参数只是Thread::Conveyor对象的数组引用:

my $data = AbstractHash->tie ( \@a1, \@a2, \$tcq );

其中构造函数在AbstractHash包中定义:

sub tie {

    my $class = shift;  # Implicit variable, don't forget

    my $data = {
                 someArray => +shift,
                 queues    => +shift,
                 someValue => +shift,
               };

    # $data starts life as a hashref, make it an 'AbstractHash'

    bless $data, $class; # $data is no longer a hashref
    return $data;        # AbstractHash object returned
}
于 2010-11-03T13:15:46.237 回答