我意识到以太坊中有几个这样的问题,但我无法解决我的问题。也许我应该提高我的横向思维。
我有一个正在测试的模块。这个模块看起来像:
package MyModule;
use strict;
use warnings;
... # a bunch of 'use/use lib' etc.
sub new {
my $class = shift;
my ($name,$options) = @_;
my $self = {
_name => $name,
_features => $options,
_ids => undef,
_groups => undef,
_status => undef,
};
bless $self,$class;
return $self;
}
sub init {
my ($self) = @_;
my ($ids,$groups,$status) = ...; # these are from a working module
$self->{_ids} = $ids;
$self->{_groups} = $groups;
$self->{_status} = $status;
return $self;
}
这是我的测试文件:
#!/usr/bin/perl -w
use strict;
use MyModule;
use Test::More tests => 1;
use Data::Dumper;
print "Name: ";
my $name;
chomp($name = <STDIN>);
print "chosen name: $name\n";
my %options = (
option1 => 'blah blah blah',
option2 => 'blu blu blu',
);
my $name_object = MyModule->new($name,\%options);
print Dumper($name_object);
isa_ok($name_object,'MyModule');
$name_object->init;
print Dumper($name_object);
现在它可以工作到isa_ok
,但随后出现:
Can't locate object method "init" via package "MyModule" at test_MyModule.t line 31, <STDIN> line 1.
这只是在我尝试(并且似乎有些失败)使用对象时才发生的。因此,我认为我误解了 Perl 中对象的应用程序!任何帮助,将不胜感激...