1 # Copyright (c) 2008,2009 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
7 # This program 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 General Public License
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94085, 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";
40 This module will modify C<Math::BigInt> to hide inconsistent behaviors across
41 Perl versions. Specifically, it handles the following.
47 Older versions of C<Math::BigInt>, like the one shipped with Perl 5.6.1,
48 stringify positive numbers with a leading C<+> (e.g. C<+1> instead of C<1>).
54 my $test_num = Math::BigInt->new(1);
56 our $stringify = overload::Method($test_num, '""');
57 # convince older perls that $stringify really is used
58 $stringify = $stringify;
60 if ($test_num =~ /^\+/) {
63 use overload 'eq' => sub {
64 my ($self, $other) = @_;
65 return "$self" eq "$other";
68 # stringify is already overloaded; seems to be no good way to
69 # re-overload it without triggering a warning
70 no warnings 'redefine';
72 my $str = $Amanda::BigIntCompat::stringify->(@_);
80 # the "sign" method does not exist in older versions, either, but is used
82 if (!$test_num->can("sign")) {
85 sub sign { ($_[0] =~ /^-/)? "-" : "+"; }
91 if (!$test_num->can("bstr")) {