Thanks for the reply. (I haven't been able to access this webshite for the last 3 days.)
I was a bit confused by the fact that, with Choroba's script, the overloading was unaffected by the order in which package My::A and My::B were listed.
Eventually, I deduced that the
overriding "use overload" directives were, courtesy of being inside an eval block, not executed until after both packages had loaded.
Anyway, I've been playing around with this approach and finding it to be relatively simple.
I've decided that the implementation should be effected by a standalone module (Math::GMP_OLOAD) which will handle the Math::GMP side of things regarding the handling of Math::GMP objects in Math::MPFR, Math::GMPq and Math::GMPz.
So it will contain stuff like:
{
package Math::GMP;
use overload "+" => sub ($$$) {
my($x, $y) = (shift, shift);
if(ref($y) eq 'Math::MPFR' || ref($y) eq 'Math::GMPq' || ref($y)
+ eq 'Math::GMPz') {
return $y + $x;
}
return Math::GMP::op_add($x, $y, 0);
};
use overload "-" => sub ($$$) {
my($x, $y) = (shift, shift);
if(ref($y) eq 'Math::MPFR' || ref($y) eq 'Math::GMPq' || ref($y)
+ eq 'Math::GMPz') {
return -($y - $x);
}
return Math::GMP::op_sub($x, $y, shift);
};
....
Seems to be working ok.
I doubt that anyone else will make much use of it, but I might use it a bit - and it's an enjoyable little exercise, anyway.
It's nearly all done outside of the 3 modules it's supporting - ie it adds negligible clutter to those 3 modules.
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.