我知道有这样出来的醚几个问题,但我不能为我的问题的解决方案。 也许我应该提高自己的水平思考。
我有我测试的模块。 这个模块看起来是这样的:
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的应用程序! 任何帮助,将不胜感激...