Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: OO-call bug uncovered & autovivified functions: defined? exists?

by ysth (Canon)
on Oct 29, 2007 at 02:25 UTC ( [id://647781]=note: print w/replies, xml ) Need Help??


in reply to OO-call bug uncovered & autovivified functions: defined? exists?

What do you mean by autovivify? Autovivification in the traditional sense (dereferencing something undefined and having the appropriate type of reference be automatically generated) doesn't seem to apply to code dereferences. But you seem to be talking about named subs, not code references at all?

exists can indeed be used on subs; go back and reread the documentation. It takes the form exists &foo or exists &{foo}, where foo is the name of a sub (sans sigil) or a simple scalar variable containing a code reference or (2nd form only) an arbitrary expression yielding a code reference.

Update: just read through your code example. IMO there are no bugs there; you are created an undefined sub KA::boom. Such a sub takes precedence over a parent's boom. This can be useful in the case of a class using AUTOLOAD:

package Parent; sub boom { die "please don't call me" } package Child; sub boom; # exists but not defined, same as your \&boom but created at + compile time sub DESTROY {} sub AUTOLOAD { die "call me instead" } package main; bless({},"Child")->boom

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2025-07-20 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.