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