blessed v unblessed references
Randy J. Ray
rjray at blackperl.com
Fri May 2 11:04:33 BST 2008
Dirk Koopman wrote:
> How do you safely tell whether a reference is blessed or not? When I say
> safely, I mean without the runtime aborting.
If you don't want to load Scalar::Util, there's something I call the "Can-Can
Test". Fortunately, you don't actually have to dance a Can-Can (you do have to
use the UNIVERSAL::* space, though):
if (UNIVERSAL::can($ref, 'can')) # It's a blessed ref
Anything that's a blessed ref can call the method ->can. Unblessed references
can't.
Randy
--
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Randy J. Ray Sunnyvale, CA http://www.rjray.org rjray at blackperl.com
Silicon Valley Scale Modelers: http://www.svsm.org
More information about the london.pm
mailing list