http://www.perlmonks.org?node_id=601028


in reply to RFC: Sub::Auto - lazy loading revisited (now: AutoReloader)

Careful! This is a lot stricter than you may want it to be:

UNIVERSAL::isa($ref,'CODE') or $ref = \&{$h -> {'function'}};

Setting aside the fact that UNIVERSAL::isa() is a method and not a function, you're disallowing blessed coderefs (perhaps unnecessarily) and you're forbidding overloading (definitely unnecessarily).

If you really need to check that the underlying reference is to a subroutine, use Scalar::Util's reftype(). If all you want to do is check that you can use something as a subroutine reference appropriately, use:

if ( eval { defined &$ref } ) { ... };

Replies are listed 'Best First'.
Re^2: RFC: Sub::Auto - lazy loading revisited
by shmem (Chancellor) on Feb 20, 2007 at 10:46 UTC
    Thanks, Scalar::Util's reftype is the way to go. The sub require returns could be blessed, indeed - but overloaded? hmm...

    Or do you mean, failure if UNIVERSAL::isa is overloaded?

    <update>

    Still musing whether to patch AutoLoader...

    </update>

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re^2: RFC: Sub::Auto - lazy loading revisited
by ysth (Canon) on Feb 20, 2007 at 07:19 UTC
    exists &$ref, not defined &$ref:
    $ perl -we'sub AUTOLOAD {1} sub foo; print main->foo, 0+exists&foo, 0+ +defined&foo' 110