1# -*- mode: perl; -*- 2 3package Math::BigInt::Trace; 4 5use strict; 6use warnings; 7 8use Exporter; 9use Math::BigInt; 10 11our @ISA = qw(Exporter Math::BigInt); 12 13our $VERSION = '0.66'; 14 15use overload; # inherit overload from Math::BigInt 16 17# Globals 18our $accuracy = undef; 19our $precision = undef; 20our $round_mode = 'even'; 21our $div_scale = 40; 22 23sub new { 24 my $proto = shift; 25 my $class = ref($proto) || $proto; 26 27 my $value = shift; 28 29 my $a = $accuracy; 30 $a = $_[0] if defined $_[0]; 31 32 my $p = $precision; 33 $p = $_[1] if defined $_[1]; 34 35 my $self = $class -> SUPER::new($value, $a, $p, $round_mode); 36 37 printf "Math::BigInt new '%s' => '%s' (%s)\n", 38 $value, $self, ref($self); 39 40 return $self; 41} 42 43sub import { 44 my $class = shift; 45 46 printf "%s -> import(%s)\n", $class, join(", ", @_); 47 48 # we catch the constants, the rest goes to parent 49 50 my $constant = grep { $_ eq ':constant' } @_; 51 my @a = grep { $_ ne ':constant' } @_; 52 53 if ($constant) { 54 overload::constant 55 56 integer => sub { 57 $class -> new(shift); 58 }, 59 60 float => sub { 61 $class -> new(shift); 62 }, 63 64 binary => sub { 65 # E.g., a literal 0377 shall result in an object whose value 66 # is decimal 255, but new("0377") returns decimal 377. 67 return $class -> from_oct($_[0]) if $_[0] =~ /^0_*[0-7]/; 68 $class -> new(shift); 69 }; 70 } 71 72 $class -> SUPER::import(@a); # need it for subclasses 73 #$self -> export_to_level(1, $class, @_); # need this ? 74} 75 761; 77