1#!perl 2 3package Math::BigInt::Subclass; 4 5require 5.005_02; 6 7use strict; 8use warnings; 9 10use Exporter; 11use Math::BigInt 1.64; 12 13# $lib is for the "lib => " test 14our $lib; 15our ($accuracy, $precision, $round_mode, $div_scale); 16 17our @ISA = qw(Exporter Math::BigInt); 18our @EXPORT_OK = qw(bgcd objectify); 19 20our $VERSION = "0.05"; 21 22use overload; # inherit overload from BigInt 23 24# Globals 25$accuracy = $precision = undef; 26$round_mode = 'even'; 27$div_scale = 40; 28$lib = ''; 29 30sub new { 31 my $proto = shift; 32 my $class = ref($proto) || $proto; 33 34 my $value = shift; 35 my $a = $accuracy; $a = $_[0] if defined $_[0]; 36 my $p = $precision; $p = $_[1] if defined $_[1]; 37 my $self = Math::BigInt->new($value, $a, $p, $round_mode); 38 bless $self, $class; 39 $self->{'_custom'} = 1; # make sure this never goes away 40 return $self; 41} 42 43sub bgcd { 44 Math::BigInt::bgcd(@_); 45} 46 47sub blcm { 48 Math::BigInt::blcm(@_); 49} 50 51sub as_int { 52 Math::BigInt->new($_[0]); 53} 54 55BEGIN { 56 *objectify = \&Math::BigInt::objectify; 57 58 # these are called by AUTOLOAD from BigFloat, so we need at least these. 59 # We cheat, of course.. 60 *bneg = \&Math::BigInt::bneg; 61 *babs = \&Math::BigInt::babs; 62 *bnan = \&Math::BigInt::bnan; 63 *binf = \&Math::BigInt::binf; 64 *bzero = \&Math::BigInt::bzero; 65 *bone = \&Math::BigInt::bone; 66} 67 68sub import { 69 my $self = shift; 70 71 my @a; 72 my $t = 0; 73 foreach (@_) { 74 # remove the "lib => foo" parameters and store it 75 if ($t == 1) { 76 $lib = $_; 77 $t = 0; 78 next; 79 } 80 if ($_ eq 'lib') { 81 $t = 1; 82 next; 83 } 84 push @a, $_; 85 } 86 $self->SUPER::import(@a); # need it for subclasses 87 $self->export_to_level(1, $self, @a); # need this ? 88} 89 901; 91