[CDBI] Best way to tell if two objects are the same?

William Ross will at spanner.org
Wed Jan 11 21:32:31 GMT 2006


On 11 Jan 2006, at 18:50, Bill Moseley wrote:

> On Wed, Jan 11, 2006 at 06:18:28PM +0000, William Ross wrote:
>> just calling id() should work for single-column keys, but with mcpk
>> you would need to call it in list context and compare the lists you
>> get back. The easier way to do essentially the same thing is to call
>> stringify_self() (in which case you can manage special cases by
>> defining a Stringify column set) or _live_object_key() (which also
>> includes the class name).
>
> I need a general case so I'm not sure I can trust Stingify.  Object
> can stringify to anything.  Also, _live_object_key is a newer method.
>
>>
>> The overload does seem like a good idea. Maybe just:
>>
>>   use overload 'cmp' => sub { $_[0]->_live_object_key cmp $_[1]-
>>> _live_object_key };
>
> Yes, that would be a nice feature.  Not sure what I'd expect 'cmp',
> '==' or 'eq', though.

all the string comparison operators are derived from cmp: overload  
that and you get them all (including eq). likewise <=> gives you all  
the numerical comparisons (==, >=, etc).

> Should this die?  Or it return false?  Or compare against what ever
> the object is stringified to?
>
>     if ( $cdbi_object eq 'constant' )

good point. I suppose the existing "" overload would normally be  
called in that case? which seems like an excellent reason for not  
overloading cmp. It can still be made to work, but you'd have to test  
both sides for cdbi-objectness and it would get a lot less neat.

will





More information about the ClassDBI mailing list