1# -*- mode: perl; -*- 2# 3# Verify that 4# - Math::BigInt::objectify() calls as_int() (or as_number(), as a fallback) 5# if the target object class is Math::BigInt. 6# - Math::BigInt::objectify() calls as_float() if the target object class is 7# Math::BigFloat. 8# 9# See RT #16221 and RT #52124. 10 11use strict; 12use warnings; 13 14package main; 15 16use Test::More tests => 2; 17use Math::BigInt; 18use Math::BigFloat; 19 20############################################################################ 21 22my $int = Math::BigInt->new(10); 23my $int_percent = My::Percent::Float->new(100); 24 25is($int * $int_percent, 10, '$int * $int_percent = 10'); 26 27############################################################################ 28 29my $float = Math::BigFloat->new(10); 30my $float_percent = My::Percent::Float->new(100); 31 32is($float * $float_percent, 10, '$float * $float_percent = 10'); 33 34############################################################################ 35 36package My::Percent::Int; 37 38sub new { 39 my $class = shift; 40 my $num = shift; 41 return bless \$num, $class; 42} 43 44sub as_number { 45 my $self = shift; 46 return Math::BigInt->new($$self / 100); 47} 48 49sub as_string { 50 my $self = shift; 51 return $$self; 52} 53 54############################################################################ 55 56package My::Percent::Float; 57 58sub new { 59 my $class = shift; 60 my $num = shift; 61 return bless \$num, $class; 62} 63 64sub as_int { 65 my $self = shift; 66 return Math::BigInt->new($$self / 100); 67} 68 69sub as_float { 70 my $self = shift; 71 return Math::BigFloat->new($$self / 100); 72} 73 74sub as_string { 75 my $self = shift; 76 return $$self; 77} 78