Why shouldn't I use UNIVERSAL::isa?

前端 未结 7 1021
终归单人心
终归单人心 2021-02-07 07:58

According to this

http://perldoc.perl.org/UNIVERSAL.html

I shouldn\'t use UNIVERSAL::isa() and should instead use $obj->isa() or CLASS->isa().

This means

7条回答
  •  时光说笑
    2021-02-07 08:23

    See the docs for UNIVERSAL::isa and UNIVERSAL::can for why you shouldn't do it.

    In a nutshell, there are important modules with a genuine need to override 'isa' (such as Test::MockObject), and if you call it as a function, you break this.

    I have to say, my $self = shift if UNIVERSAL::isa($_[0], __PACKAGE__) doesn't look terribly clean to me - anti-Perl advocates would be complaining about line noise. :)

提交回复
热议问题