Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
If Foo inherits from Bar, and Bar defines an AUTOLOAD, then both undefined functions and methods in Foo can trigger Bar::AUTOLOAD. In some situations Bar::AUTOLOAD really wants to do different things on a function call than a method call. (Like issue a warning for a function, and try to handle methods.)

Which raises the issue of how you tell them apart.

Unfortunately caller doesn't do the trick. One approach that I thought of was Devel::Caller, but its test suite fails on my machine. (And it has documented serious limits.) There is a warning Use of inherited AUTOLOAD for non-method %s() is deprecated that is triggered exactly when I want to distinguish the cases. I don't know how to get at that, and it might be turned off. (Turning it on and trapping it could work, if I could think of a way to guarantee that behaviour.)

That leaves heuristics. If the first argument is blessed (testable with Scalar::Util) then it is a pretty safe bet that it is meant as a method call. Conversely if the first argument is the name of a package that exists, I'd guess that that is meant as a method call. What would people prefer to see assumed, though, if the string is one that plausibly could be a package (ie it matches a pattern like /^\w+(?:::\w+)*(?:::)?\z/). Should I assume that it is a method call on a package that doesn't yet exist, or assume that it is a function call? Or don't assume and make my error message ambiguous??

For the curious, this is for a proof of concept UNIVERSAL::AUTOLOAD_CAN, as described in Re: Re: Why breaking can() is acceptable.


In reply to Detecting function vs method in an AUTOLOAD? by tilly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-24 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found