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

[prev] [thread] [next] [Date index for 2006/01/11]

From: William Ross
Subject: Re: [CDBI] Best way to tell if two objects are the same?
Date: 21:32 on 11 Jan 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


_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

Re: [CDBI] Best way to tell if two objects are the same?
William Ross 21:32 on 11 Jan 2006

Generated at 09:31 on 23 Jan 2006 by mariachi v0.52