Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Workings of UNIVERSAL::can

by Somni (Friar)
on Jul 06, 2011 at 22:48 UTC ( [id://913095]=note: print w/replies, xml ) Need Help??


in reply to Workings of UNIVERSAL::can

The algorithm is a simple symbol table search in method resolution order.

If the method is not in the symbol table (perhaps it's loaded with AUTOLOAD, or otherwise loaded after the ->can call) it won't be found. If it's loaded via AUTOLOAD, the module itself will need to overload can so it can answer effectively for those functions; this is somewhat tricky to get right, as you need to allow the search to continue further up the tree as necessary.

You mentioned later that ->can is not seeing your C++ functions. Unless these are exposed to the Perl level, they won't be in the symbol table; but then again, you shouldn't be able to call them from Perl, either, so finding them with ->can is simply wrong. If this is the case, you'll need to elaborate more as to what's going on.

Replies are listed 'Best First'.
Re^2: Workings of UNIVERSAL::can
by Anonymous Monk on Jul 06, 2011 at 23:37 UTC

    The algorithm is a simple symbol table search in method resolution order.

    Hi :D

    Actually :) Method resolution order is not an algorithm (or an actual order) or any more than symbol table search is an algorithm.

    Or put another way, a sort-algorithm is not an actual algorithm, but a bubble-sort-algorithm is an sort-algorithm; is an algorithm.

    Perl's default method-resolution-order, algorithm , is a linear-depth-first-search.

    You can change that in modern perls with the mro pragma to C3 linearization

      The fact that mro is changeable is why I said method resolution order, and not a specific order.

      Taken individually, each of the items is not an algorithm. Taken together (symbol table search in method resolution order), it is an algorithm, though ill-specified due to the variable of which mro is in effect.

        Taken individually, each of the items is not an algorithm. Taken together (symbol table search in method resolution order), it is an algorithm, though ill-specified due to the variable of which mro is in effect.

        No, taken together, it is still not an algorithm. An algorithm is well-defined by definition.

        Also, its just repeating the question back at the original poster. The answer might work for "how do I print $foo?" (well, you print $foo;), but not here.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found