1 # Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
20 package Amanda::BigIntCompat;
29 Amanda::BigIntCompat -- make C<Math::BigInt> behave consistently
33 use Amanda::BigIntCompat;
36 my $bn = Math::BigInt->new(1);
37 print "okay\n" if $bn eq "1";
41 This module will modify C<Math::BigInt> to hide inconsistent behaviors across
42 Perl versions. Specifically, it handles the following.
48 Older versions of C<Math::BigInt>, like the one shipped with Perl 5.6.1,
49 stringify positive numbers with a leading C<+> (e.g. C<+1> instead of C<1>).
55 my $test_num = Math::BigInt->new(1);
57 our $stringify = overload::Method($test_num, '""');
58 # convince older perls that $stringify really is used
59 $stringify = $stringify;
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")) {