summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MANIFEST1
-rw-r--r--dist/Math-BigRat/lib/Math/BigRat.pm12
-rw-r--r--dist/Math-BigRat/t/bitwise.t15
3 files changed, 27 insertions, 1 deletions
diff --git a/MANIFEST b/MANIFEST
index 5a17254a94..fa2698f370 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -2886,6 +2886,7 @@ dist/Math-BigRat/t/bigratpm.t Math::BigRat test
dist/Math-BigRat/t/bigrat.t Math::BigRat test
dist/Math-BigRat/t/bigratup.t test under $Math::BigInt::upgrade
dist/Math-BigRat/t/bigroot.t Math::BigRat test
+dist/Math-BigRat/t/bitwise.t Math::BigRat test
dist/Math-BigRat/t/hang.t Math::BigRat test for bug #34584 - hang in exp()
dist/Math-BigRat/t/Math/BigRat/Test.pm Math::BigRat test helper
dist/Math-BigRat/t/requirer.t see if require works properly
diff --git a/dist/Math-BigRat/lib/Math/BigRat.pm b/dist/Math-BigRat/lib/Math/BigRat.pm
index 3508bf94f0..92cc59c2be 100644
--- a/dist/Math-BigRat/lib/Math/BigRat.pm
+++ b/dist/Math-BigRat/lib/Math/BigRat.pm
@@ -16,6 +16,7 @@ package Math::BigRat;
# anythig older is untested, and unlikely to work
use 5.006;
use strict;
+use Carp ();
use Math::BigFloat;
use vars qw($VERSION @ISA $upgrade $downgrade
@@ -26,7 +27,16 @@ use vars qw($VERSION @ISA $upgrade $downgrade
$VERSION = '0.26';
$VERSION = eval $VERSION;
-use overload; # inherit overload from Math::BigFloat
+# inherit overload from Math::BigFloat, but disable the bitwise ops that don't
+# make much sense for rationals unless they're truncated or something first
+
+use overload
+ map {
+ my $op = $_;
+ ($op => sub {
+ Carp::croak("bitwise operation $op not supported in Math::BigRat");
+ });
+ } qw(& | ^ ~ << >> &= |= ^= <<= >>=);
BEGIN
{
diff --git a/dist/Math-BigRat/t/bitwise.t b/dist/Math-BigRat/t/bitwise.t
new file mode 100644
index 0000000000..be9aa4ce38
--- /dev/null
+++ b/dist/Math-BigRat/t/bitwise.t
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+use Test::More tests => 22;
+
+use Math::BigRat;
+
+my $x = Math::BigRat->new('3/7');
+
+for my $op (qw(& | ^ << >> &= |= ^= <<= >>=)) {
+ ok !eval "my \$y = \$x $op 42; 1";
+ like $@, qr/^bitwise operation \Q$op\E not supported in Math::BigRat/;
+}
+
+ok !eval "my \$y = ~\$x; 1";
+like $@, qr/^bitwise operation ~ not supported in Math::BigRat/;