1 # Copyright (c) 2005-2008 Zmanda, Inc. All Rights Reserved.
3 # This library is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU Lesser General Public License version 2.1 as
5 # published by the Free Software Foundation.
7 # This library is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10 # License for more details.
12 # You should have received a copy of the GNU Lesser General Public License
13 # along with this library; if not, write to the Free Software Foundation,
14 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16 # Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19 package Amanda::BigIntCompat;
28 Amanda::BigIntCompat -- make C<Math::BigInt> behave consistently
32 use Amanda::BigIntCompat;
35 my $bn = Math::BigInt->new(1);
36 print "okay\n" if $bn eq "1";
44 This module will modify C<Math::BigInt> to hide inconsistent behaviors across
45 Perl versions. Spefically, it handles the following.
51 Older versions of C<Math::BigInt>, like the one shipped with Perl 5.6.1,
52 stringify positive numbers with a leading C<+> (e.g. C<+1> instead of C<1>).
58 my $test_num = Math::BigInt->new(1);
59 our $stringify = overload::Method($test_num, '""');
61 if ($test_num =~ /^\+/) {
64 use overload 'eq' => sub {
65 my ($self, $other) = @_;
66 return "$self" eq "$other";
69 # stringify is already overloaded; seems to be no good way to
70 # re-overload it without triggering a warning
71 no warnings 'redefine';
73 my $str = $Amanda::BigIntCompat::stringify->(@_);
81 # the "sign" method does not exist in older versions, either, but is used
83 if (!$test_num->can("sign")) {
86 sub sign { ($_[0] =~ /^-/)? "-" : "+"; }
92 if (!$test_num->can("bstr")) {