Calling base constructor in perl

前端 未结 3 580
走了就别回头了
走了就别回头了 2021-02-01 05:05

What is the correct way to call the base constructor from the class constructor in Perl ?

I have seen syntax like this:

 my $class = shift; 
 my $a = sh         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 05:58

    When using multiple inheritance, the default method resolution order is sub-par. I strongly recommend that you add

    use mro 'c3';
    

    to the modules and that you call the next constructor in the chain using

    sub new {
       my ($class) = @_;
       return $class->next::method(@_);
    }
    

    Alpha and Beta would have to do the same for this to work.

    Ref: mro

提交回复
热议问题