On Sun, Feb 25, 2007 at 23:22:13 -0800, Joshua ben Jore wrote: > Ick!!!! Neither ref nor blessed have never been a booleans before and > even this doesn't change that. Ref couldn't even used to decide if you > had an object because the two false values '' and '0' can both be > returned by objects: > > ok( ref( bless( ..., "\0" ) ), 'Detected object' ) # fails > ok( ref( bless( ..., 0 ) ), 'Detected object' ) # fails > > The only boolean you'll ever have on Perl 5 is defined( blessed( ... ) > ). It's a bad pattern to rely on ref(). Or... all '' and '0' using > classes were using UNIVERSAL::ref then... maybe... ref() could be > considered a boolean. I'd have to be convinced.
But do you have an alternative? ;-) Realistically, blessing as "0" is intended to make if ( ref $x ) ) return false (at least the one crazy person who did that and released it on the CPAN intended it to be this way ;-), and blessing to "\0" probably works similarly. From perldoc: ref Returns a nonâempty string if EXPR is a reference, the empty string otherwise. I suppose if ( length( ref $x ) ) { } is a better test, but when have you ever seen that? I don't think i'll start using it. -- Yuval Kogman <[EMAIL PROTECTED]> http://nothingmuch.woobling.org 0xEBD27418
pgpsBqvuuswWZ.pgp
Description: PGP signature