由于某种原因,我无法访问边界对象上的子方法。我希望尽可能详细地给出答案,因为我仍然对 perl 的继承感到有些困惑,尤其是祝福部分。此外,任何建设性的批评都对整体设计很有帮助。
Generic.pm(基类)
package AccessList::Generic;
use strict;
use warnings;
sub new {
my $class = shift;
my $self = {
rules => [],
@_
};
bless $self, $class;
return $self;
}
sub get_line_count {
my $self = shift;
return scalar @{$self->{rules}};
}
1;
扩展.pm
package AccessList::Extended;
use strict;
use warnings;
use AccessList::Generic;
use base qw(AccessList::Generic);
sub new {
my ($class, @args) = @_;
my $self = $class->SUPER::new(@args);
return $self;
}
1;
边界.pm
package AccessList::Extended::Boundary;
use strict;
use warnings;
use AccessList::Extended;
use base qw(AccessList::Extended);
sub new {
my ($class, @args) = @_;
my $self = $class->SUPER::new(@args);
return $self;
}
sub get_acl_information {
my ($self) = @_;
return;
}
1;
未通过测试
can_ok('AccessList::Extended::Boundary', 'get_acl_information');
错误信息
# Failed test 'AccessList::Extended::Boundary->can('get_acl_information')'
# at t/b1.t line 42.
# AccessList::Extended::Boundary->can('get_acl_information') failed
# Looks like you failed 1 test of 2.