Subject: | Math::Currency Operator Comparisons Failing since Math-BigInt-1.999718 |
Greetings,
Since Math::BigInt v1.999718 all operator comparisons using Math::Currency objects are now failing:
cmp_ok( Math::Currency->new('19.95'), '==', Math::Currency->new('19.95'), 'Object == Object' );
not ok 1 - Object == Object
# Failed test 'Object == Object'
# at t/007_comparision.t line 12.
# got: 19.95
# expected: 19.95
This was caused by the following noted change in Math::BigInt:
2016-04-22 v1.999718 pjacklam
* Add overloading of '==', '!=', '<', '<=', '>', to to Math::BigInt and
Math::BigFloat and fix the broken overloading of '>='. These overloaded
operators now behave like the equivalent core Perl operators.
(via Bisection I am able to confirm that v1.999717 works with Math::Currency while v1.999718 does not).
I've gone ahead and created a failing test (attached as t/007_comparision.t) and a patch to Math::Currency that resolves the issue (attached as bcmp.patch).
Hopefully this patch can be applied and the test added so that we have a nice regression test. I've tried to write the test in your style to minimize the amount of work needed on your side.
Please feel free to reach out to me if you need more information, wish to discuss, or if I can be of any assistance.
Thank you!
Subject: | 007_comparision.t |
use Test::More qw(no_plan);
BEGIN { use_ok('Math::Currency') };
# For subsequent testing, we need to make sure that format is default US
Math::Currency->format('USD');
subtest '==' => sub {
my $object = Math::Currency->new('19.95');
my $scalar = 19.95;
cmp_ok( $object, '==', $object, 'Object == Object' );
cmp_ok( $scalar, '==', $object, 'Scalar == Object' );
cmp_ok( $object, '==', $scalar, 'Object == Scalar' );
ok( !( Math::Currency->new('19.95') == Math::Currency->new('15.00') ), 'Object != Object' );
};
subtest '<=' => sub {
subtest '==' => sub {
my $object = Math::Currency->new('19.95');
my $scalar = 19.95;
cmp_ok( $object, '<=', $object, 'Object == Object' );
cmp_ok( $scalar, '<=', $object, 'Scalar == Object' );
cmp_ok( $object, '<=', $scalar, 'Object == Scalar' );
ok( !( Math::Currency->new('19.95') <= Math::Currency->new('15.00') ), 'Object (!)<= Object' );
};
subtest '<=' => sub {
my $lesser_object = Math::Currency->new('15.00');
my $lesser_scalar = 15.00;
my $greater_object = Math::Currency->new('19.95');
my $greater_scalar = 19.95;
cmp_ok( $lesser_object, '<=', $greater_object, 'Object <= Object' );
cmp_ok( $lesser_scalar, '<=', $greater_object, 'Scalar <= Object' );
cmp_ok( $lesser_object, '<=', $greater_scalar, 'Object <= Scalar' );
ok( !( $greater_object <= $lesser_object ), 'Object (!)<= Object' );
};
};
subtest '>=' => sub {
subtest '==' => sub {
my $object = Math::Currency->new('19.95');
my $scalar = 19.95;
cmp_ok( $object, '>=', $object, 'Object == Object' );
cmp_ok( $scalar, '>=', $object, 'Scalar == Object' );
cmp_ok( $object, '>=', $scalar, 'Object == Scalar' );
ok( !( Math::Currency->new('15.00') >= Math::Currency->new('19.95') ), 'Object (!)>= Object' );
};
subtest '>=' => sub {
my $lesser_object = Math::Currency->new('15.00');
my $lesser_scalar = 15.00;
my $greater_object = Math::Currency->new('19.95');
my $greater_scalar = 19.95;
cmp_ok( $lesser_object, '>=', $lesser_object, 'Object >= Object' );
cmp_ok( $lesser_scalar, '>=', $lesser_object, 'Scalar >= Object' );
cmp_ok( $lesser_object, '>=', $lesser_scalar, 'Object >= Scalar' );
ok( !( $lesser_object >= $greater_object ), 'Object (!)>= Object' );
};
};
Subject: | bcmp.patch |
--- lib/Math/Currency.org.pm 2016-06-10 13:41:55.370303622 -0500
+++ lib/Math/Currency.pm 2016-06-10 13:42:02.464231293 -0500
@@ -314,7 +314,7 @@
# we override the default here because we only want to compare the precision of
# the currency we're dealing with, not the precision of the underlying object
sub bcmp {
- my $class = shift;
+ my $class = __PACKAGE__;
# make sure we're dealing with two Math::Currency objects
my ( $x, $y ) =
map { ref $_ ne $class ? $class->new($_) : $_ } @_[ 0, 1 ];