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: 18:18 on 11 Jan 2006
On 11 Jan 2006, at 15:10, Bill Moseley wrote:

> On Wed, Jan 11, 2006 at 09:42:59AM -0500, Michael Peters wrote:
>>> I need to know if $obj1 eq $obj2, and I'm wondering the best way.  I
>>> suppose ref($obj1) eq ref($obj2) would fail without Live_Object  
>>> index.
>>
>> You mean if they are the same object or refer to the same row in  
>> the database.
>> If object, then simply comparing the address given by  
>> Scalar::Util::refaddr
>> would be enough.
>
> That relies on Live_Object index being in use (to see if they point to
> the same row), IIUC.
>
>> If you want to check if they are the same row in the db, then you  
>> could compare
>> their table() and id() to see if they are the same.
>>
>> Is that what you were asking for?
>
> I just thought that it might be a common operation.  I kind of
> expected for there to be a CDBI method available, then I saw that code
> that generates the unique key for %Live_Object is inlined.
>
> Might be a nice use for '==' overload.

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).

The overload does seem like a good idea. Maybe just:

   use overload 'cmp' => sub { $_[0]->_live_object_key cmp $_[1]- 
 >_live_object_key };

I'm stuck trying to add proper access control to php muppetware so I  
can't test any of this :(

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 18:18 on 11 Jan 2006

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