Actually submit previous change.
[p5sagit/p5-mst-13.2.git] / t / lib / Math / BigInt / Subclass.pm
CommitLineData
dccbb853 1#!/usr/bin/perl -w
2
3package Math::BigInt::Subclass;
4
5require 5.005_02;
6use strict;
7
8use Exporter;
990fb837 9use Math::BigInt (1.64);
10# $lib is for the "lib => " test
dccbb853 11use vars qw($VERSION @ISA $PACKAGE @EXPORT_OK
990fb837 12 $lib
dccbb853 13 $accuracy $precision $round_mode $div_scale);
14
15@ISA = qw(Exporter Math::BigInt);
8f675a64 16@EXPORT_OK = qw(bgcd objectify);
dccbb853 17
990fb837 18$VERSION = 0.04;
b3abae2a 19
20use overload; # inherit overload from BigInt
dccbb853 21
22# Globals
23$accuracy = $precision = undef;
24$round_mode = 'even';
25$div_scale = 40;
990fb837 26$lib = '';
dccbb853 27
28sub new
29{
30 my $proto = shift;
31 my $class = ref($proto) || $proto;
32
394e6ffb 33 my $value = shift;
61f5c3f5 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;
dccbb853 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
8f675a64 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
dccbb853 66sub import
67 {
68 my $self = shift;
8f675a64 69
70 my @a; my $t = 0;
71 foreach (@_)
72 {
990fb837 73 # remove the "lib => foo" parameters and store it
74 $lib = $_, $t = 0, next if $t == 1;
8f675a64 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 ?
dccbb853 83 }
84
851;