LanX has asked for the wisdom of the Perl Monks concerning the following question:

saw this in Algorithm::Loops

DB<71> $code = sub {} DB<72> p ref $code CODE DB<73> *isa = \&UNIVERSAL::isa # import DB<74> p isa($code,"CODE") # ??? 1 DB<75>

Where is this behavior of isa() documented and why would one want to do this?

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re: isa for ref?
by tobyink (Canon) on Jun 20, 2020 at 22:14 UTC

    It's documented towards the end of UNIVERSAL. And you don't want to do it. isa is a method, not a function.

      isa is a method, not a function.
      SCNR: Unless you're running Perl 5.32, where isa is an infix operator.
Re: isa for ref?
by choroba (Cardinal) on Jun 20, 2020 at 22:14 UTC
    > why would one want to do this

    Maybe because of

    my $ref = bless sub {}, 'MyClass'; say ref($ref) eq 'CODE' ? 1 : 0; say UNIVERSAL::isa($ref, 'CODE') ? 1 : 0;
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      yeah, but that's why we have Scalar::Util::reftype() now

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery