xref: /openbsd-src/gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigInt/Subclass.pm (revision 898184e3e61f9129feb5978fad5a8c6865f00b92)
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
52sub as_int
53  {
54  Math::BigInt->new($_[0]);
55  }
56
57BEGIN
58  {
59  *objectify = \&Math::BigInt::objectify;
60
61  # these are called by AUTOLOAD from BigFloat, so we need at least these.
62  # We cheat, of course..
63  *bneg = \&Math::BigInt::bneg;
64  *babs = \&Math::BigInt::babs;
65  *bnan = \&Math::BigInt::bnan;
66  *binf = \&Math::BigInt::binf;
67  *bzero = \&Math::BigInt::bzero;
68  *bone = \&Math::BigInt::bone;
69  }
70
71sub import
72  {
73  my $self = shift;
74
75  my @a; my $t = 0;
76  foreach (@_)
77    {
78    # remove the "lib => foo" parameters and store it
79    $lib = $_, $t = 0, next if $t == 1;
80    if ($_ eq 'lib')
81      {
82      $t = 1; 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