Re: No overload magic

[prev] [thread] [next] [Date index for 2005/02/16]

From: Michele Valzelli
Subject: Re: No overload magic
Date: 11:59 on 16 Feb 2005
On Wed, 16 Feb 2005 10:05:41 +0000, William Ross <will@xxxxxxx.xxx> wrote:
> On 16 Feb 2005, at 07:55, Karjala wrote:
> 
> > It's been said before on this list
> > (http://www.spanner.org/lists/cdbi/2004/09/15/7c3cf0f4.html)
> >
> > ...but I'd like to offer my feedback also.
> >
> > When I do comparisons between CDBI objects ($obj1 == $obj2), it worked
> > fine under cdbi 0.95 (it compared their keys), but it only sometimes
> > works under cdbi 0.96 (the rest of the times, it causes the error
> > message described in the linked message above).
> >
> > I think this is a bug.
> 
> In the message you cite the author was trying to perform comparisons on
> cdbi objects and assuming that ($x > $y) is the same as ($x->id >
> $y->id). There's no reason why that assumption should be correct: not
> all classes have a single key, and it's just as likely that you would
> want to compare some other column or a computed value, so cdbi leaves
> you to specify your own overloading. You can do that by adding more
> 'use overload' instructions at the top of your data classes or base
> class:
> 
> use overload
>         '>' => sub { shift->id },
>         '<' => sub { shift->id },
>         '==' => sub { shift->stringify_self },
>         fallback => 1;
> 
> looking at the code, you can also specify the column(s) that a class
> stringifies to, which is a very nice touch. perhaps just adding:
> 
> My::Thing->columns(Stringify => qw(id));
> 
> will help?

Actually it won't help.

I too had reported the same issue
(http://groups.kasei.com/mail/arc/cdbi-talk/2004-10/msg00181.html).
The probelm here is that overloading in comparisons works correctly,
but not always.
Even more, the same code works perfectly unless run into a
Mason/mod_perl environment (all people who have reported this bug was
using Mason, i noticed this today).

I think this is a bug, (as mentioned bt Tim Bunce in this message
http://groups.kasei.com/mail/arc/cdbi-talk/2004-10/msg00181.html) but
now i just wonder whether it is class-dbi,mod_perl or mason related.

My solution was to track down all such comparisons, and replace them
with the long version, since i had this kind of problems on a
production environment. Bt i'd really like to see this solved, since
sometimes i tend to forget about it and introduce it in new code (not
to metion that the code gets really uglier this way!).

        -- 
        tell my friends I'm on vacation
and say that I'm OK
just wanna sleep all day

No overload magic
Karjala 07:55 on 16 Feb 2005

Re: No overload magic
Karjala 08:01 on 16 Feb 2005

Re: No overload magic
William Ross 10:05 on 16 Feb 2005

Re: No overload magic
Michael G Schwern 11:25 on 16 Feb 2005

Re: No overload magic
Tony Bowden 14:10 on 16 Feb 2005

Re: No overload magic
William Ross 14:20 on 17 Feb 2005

Re: No overload magic
Michael G Schwern 06:43 on 18 Feb 2005

Re: No overload magic
Tony Bowden 08:21 on 18 Feb 2005

Re: No overload magic
Tim Bunce 09:43 on 18 Feb 2005

Re: No overload magic
Karjala 11:57 on 16 Feb 2005

Re: No overload magic
William Ross 13:52 on 16 Feb 2005

Re: No overload magic
Karjala 14:09 on 16 Feb 2005

Re: No overload magic
Michele Valzelli 11:59 on 16 Feb 2005

Re: No overload magic
Ofer Nave 21:53 on 16 Feb 2005

Re: No overload magic
Ken.Olstad 22:00 on 16 Feb 2005

Generated at 11:20 on 20 Feb 2005 by mariachi v0.52