Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: RFC: Sub::Auto - lazy loading revisited

by chromatic (Archbishop)
on Feb 20, 2007 at 05:47 UTC ( #601028=note: print w/replies, xml ) Need Help??

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?


    Still musing whether to patch AutoLoader...



    _($_=" "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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://601028]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2019-02-17 14:29 GMT
Find Nodes?
    Voting Booth?
    I use postfix dereferencing ...

    Results (96 votes). Check out past polls.