Skip Menu |

This queue is for tickets about the Math-BigInt-GMP CPAN distribution.

Report information
The Basics
Id: 67204
Status: rejected
Priority: 0/
Queue: Math-BigInt-GMP

People
Owner: Nobody in particular
Requestors: PWBENNETT [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.36
Fixed in: (no value)



Subject: Can't inherit from Math::BigInt::GMP
Maybe I'm doing it wrong. Maybe it's broken. Either way, I have reached the end of my Perl expertise here. Please see the FAILs here: http://matrix.cpantesters.org/?dist=Net- IPAddress-Util+0.12 What it looks like is happening, is that even though I'm putting Math::BigInt and Math::BigInt::GMP into @ISA, Math::BigInt::GMP is complaining that my derived objects are not of the right class. They're indeed not of the base class, but I'm surprised that the normal rules of Perl inheritance do not seem to apply.
Is this ticket still relevant? Math::BigInt and Math::BigInt::GMP are very different objects. They objects have a different internal structure and the classes have a completely different set of supported methods.
Subject: Re: [rt.cpan.org #67204] Can't inherit from Math::BigInt::GMP
Date: Thu, 17 Nov 2016 07:25:19 -0500
To: bug-Math-BigInt-GMP [...] rt.cpan.org
From: Paul Bennett <paul.w.bennett [...] gmail.com>
On Thu, Nov 17, 2016 at 4:36 AM, Peter John Acklam via RT <bug-Math-BigInt-GMP@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=67204 > > > Is this ticket still relevant? > > Math::BigInt and Math::BigInt::GMP are very different objects. They objects have a different internal structure and the classes have a completely different set of supported methods.
I was hoping it was relevant. Let me clarify ... I was hoping all the Math::BigInt "backends" were (at least broadly) compatible. However, the ticket is indeed moot by now. The latest version of my module[1] no longer cares which "backend" is in play, it just uses Math::BigInt and lets that module take care of any complications. [1] https://metacpan.org/source/PWBENNETT/Net-IPAddress-Util-3.027/lib/Net/IPAddress/Util.pm Having said that, I think I have some other work elsewhere that might rely on methods like bmul, badd, and band being available -- but I think they just use Math::BigInt and let that abstract away which backend is in use. Having looked into it while typing this, yes, in fact, I do have one other module that relies on that suite of methods[2], and I don't really know how to make it not rely on that suite of methods. [2] https://metacpan.org/source/PWBENNETT/Path-Hilbert-2.000/lib/Path/Hilbert/BigInt.pm
I still don't understand what the problem is. You wrote that you hope the backends were at least broadly compatible. They are. Here is an example of a module implementing a _fib() method for generating the Nth Fibonacci number. Every missing method is inherited from Math::BigInt::GMP: ---- Math/BigInt/GMP/Subclass.pm ---- #!perl package Math::BigInt::GMP::Subclass; use Math::BigInt::GMP; our @ISA = qw< Math::BigInt::GMP >; sub _fib { my ($class, $n) = @_; my $a = $class -> _zero(); return $a if $n == 0; my $b = $class -> _one(); return $b if $n == 1; for (my $i = 2 ; $i <= $n ; ++ $i) { my $c = $class -> _add($class -> _copy($a), $b); ($a, $b) = ($b, $c); } return $b; } ------------------------------------- Then you can execute the following code, which prints the 10th Fibonacci number: use Math::BigInt::GMP::Subclass; $n = Math::BigInt::GMP::Subclass -> _new("10"); $f = Math::BigInt::GMP::Subclass -> _fib($n); print Math::BigInt::GMP::Subclass _str($f), "\n"; In the example above, you could replace "GMP" with "Pari" or "FastCalc", place the .pm file in the appropriate directory and you would get exactly the same result, because you can subclass all of the backend libraries in the same way. If there is something not working as expected, please show me a concrete example and I will look into it.
CC: PWBENNETT [...] cpan.org
Subject: Re: [rt.cpan.org #67204] Can't inherit from Math::BigInt::GMP
Date: Fri, 13 Jan 2017 04:55:01 -0500
To: bug-Math-BigInt-GMP [...] rt.cpan.org
From: Paul Bennett <paul.w.bennett [...] gmail.com>
On Thu, Jan 12, 2017 at 9:34 AM, Peter John Acklam via RT <bug-Math-BigInt-GMP@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=67204 > > > I still don't understand what the problem is. You wrote that you hope the backends were at least broadly compatible. They are.
Underscored ("private") methods, eh? Nice to know, thanks! :-) The problem I was trying to solve was in Net::IPAddress::Util, but I've moved on from BigInt (to pack / unpack) for speed reasons. This bug can and probably should be closed as "not a bug". Sorry for taking up your time. What I was trying to do at the time was enable users of my module to ... use Net::IPAddress::Util try => "GMP,Pari,FastCalc"; and so on, to allow them to find out for themselves which backend was fastest on their system. As stated, it's moot now, but if you're interested, you might be able to dig around the commit history on https://github.com/PWBENNETT/Net-IPAddress-Util-backport to see what I had been trying to do (if you're curious).
Oh, I see what I was doing wrong. I was trying to implement a "one ring" solution by inheriting from BigInt itself (and fooling around in import()) instead of building one subclass for each backend. My bad. Definitely can be closed as "not a bug". Sorry again.