我意识到在以太中有几个这样的问题,但我不能解决我的问题.也许我应该改善我的横向思维.
我有一个我正在测试的模块.这个模块看起来像:
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,但随后提出:
无法通过test_MyModule.t第31行的包“MyModule”找到对象方法“init”,< STDIN>第1行.
这种情况现在才发生,我正在尝试使用对象(似乎有些失败).所以我认为我误解了Perl中对象的应用!任何帮助,将不胜感激…