I'm really on a roll here. I think I know how to fix all of
this
stuff, but there are dozens of fuctions to tackle. Please
disregard
this patch (and the previous ones, too). I'll work all this
out and
submit one big patch that does it all. Sorry for the
noise.
> Zefram wrote:
> > It works OK for plain printf "%d", but
not for addition.
> > Also doesn't work for subtraction, negation,
> > multiplication, division, remainder. Does work
for bit
> > shift and bitwise OR. Perhaps some code factoring
is
> > called for.
>
> Jerry D. Hedden wrote:
> > The attached patch adds tests for these to
lib/overload.t.
> > The tests are skipped if not using 64-bit ints.
> > The following tests (which fail for me) are set as
TODO:
> > 0+ (addition)
> > subtraction
> > multiplication
> > division
> > modulo (%)
> > exponentiation (**)
> > abs()
>
> The attached patch (which supercedes my previous
patches on
> the matter) fixes the above problem for 'abs' and
'neg'
> overloading. I added more tests as well.
>
> The patch can be check using the following:
>
> ./perl -Ilib -lwe '{ package t0; sub mynum use
> overload "0+" => &mynum, fallback
=> 1; } printf "%dn",
> abs(t0::mynum); printf "%dn", abs(bless({},
"t0"))'
>
> ./perl -Ilib -lwe '{ package t0; sub mynum use
> overload "0+" => &mynum, fallback
=> 1; } printf "%dn", -&t0::mynum;
> printf "%dn", -bless({}, "t0")'
|