1

由于某种原因,我无法访问边界对象上的子方法。我希望尽可能详细地给出答案,因为我仍然对 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.
4

1 回答 1

3

我在您发布的内容中没有看到任何问题。问题肯定出在您没有发布的内容上。您是否忘记加载 AccessList::Extended::Boundary?

$ find -type f
./AccessList/Extended/Boundary.pm
./AccessList/Extended.pm
./AccessList/Generic.pm

$ perl -E'
   use Test::More tests => 1;
   use AccessList::Extended::Boundary;
   can_ok("AccessList::Extended::Boundary", "get_acl_information");
'
1..1
ok 1 - AccessList::Extended::Boundary->can('get_acl_information')
于 2012-05-08T18:39:39.050 回答