diff options
author | Florian Ragwitz <rafl@debian.org> | 2010-11-09 19:01:51 +0100 |
---|---|---|
committer | Florian Ragwitz <rafl@debian.org> | 2010-11-09 19:03:50 +0100 |
commit | 9aa0b6486a6198e4efd3a57bb62449898e8a8139 (patch) | |
tree | 8fd8f4216cfe39585c48404ba6f09088cd293af2 /dist | |
parent | ccb84406d75e333090431f0ae31edecdf95fbad3 (diff) | |
download | perl-9aa0b6486a6198e4efd3a57bb62449898e8a8139.tar.gz |
Disable bitwise operators
Some of them used to return wrong results, others just failed horribly. We're
disabling them alltogether, with a useful error message, until maybe someone
figures out how to make them DWIM.
Diffstat (limited to 'dist')
-rw-r--r-- | dist/Math-BigRat/lib/Math/BigRat.pm | 12 | ||||
-rw-r--r-- | dist/Math-BigRat/t/bitwise.t | 15 |
2 files changed, 26 insertions, 1 deletions
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/; |