Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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?

    <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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2018-09-24 19:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (193 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!