Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: goto superclass method

by Ovid (Cardinal)
on Dec 22, 2004 at 21:21 UTC ( [id://416910]=note: print w/replies, xml ) Need Help??


in reply to Re^2: goto superclass method
in thread goto superclass method

Well, calling can directly can break if you have something in @ISA that isn't a class (such as a coderef: Class::Dynamic). Out of habit I try to call UNIVERSAL::can unless the $object->can('can');

Perhaps I'm being overly paranoid.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^4: goto superclass method
by chromatic (Archbishop) on Dec 22, 2004 at 21:53 UTC

    How do you know in general whether the object or class has its own can though? (Easy answer, but not one you'll like.)

    I prefer to use Scalar::Util's blessed to see if I can invoke operations on an object, though wrapping the call in an eval block is safer if you expect class names as well.

      I guess in this case it would be preferable to call call can as a method and let the code die and then worry about what to do if it fails. That's probably better than my silently failing or doing the wrong thing because of an overridden can.

      Cheers,
      Ovid

      New address of my CGI Course.

        My thinking is that if a superclass has overriden can(), then they have good reason to, so in a situation where you know you have a blessed ref or a package name, you should prefer calling it as a method. I only use UNIVERSAL::can directly when I'm unsure about that.

        Makeshifts last the longest.

Re^4: goto superclass method
by Joost (Canon) on Dec 22, 2004 at 21:52 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://416910]
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: (3)
As of 2024-04-26 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found