File Coverage

blib/lib/Math/GMP.pm
Criterion Covered Total %
statement 43 43 100.0
branch 9 12 75.0
condition 3 5 60.0
subroutine 15 15 100.0
pod 1 1 100.0
total 71 76 93.4


line stmt bran cond sub pod time code
1             package Math::GMP;
2              
3             # Math::GMP, a Perl module for high-speed arbitrary size integer
4             # calculations
5             # Copyright (C) 2000-2008 James H. Turner
6             # Copyright (C) 2008-2009 Greg Sabino Mullane
7              
8             # This library is free software; you can redistribute it and/or
9             # modify it under the terms of the GNU Library General Public
10             # License as published by the Free Software Foundation; either
11             # version 2 of the License, or (at your option) any later version.
12              
13             # This library is distributed in the hope that it will be useful,
14             # but WITHOUT ANY WARRANTY; without even the implied warranty of
15             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16             # Library General Public License for more details.
17              
18             # You should have received a copy of the GNU Library General Public
19             # License along with this library; if not, write to the Free
20             # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21              
22             # You can contact the author at chip@redhat.com, chipt@cpan.org, or by mail:
23              
24             # Chip Turner
25             # Red Hat Inc.
26             # 2600 Meridian Park Blvd
27             # Durham, NC 27713
28              
29 4     4   337977 use strict;
  4         44  
  4         148  
30 4     4   25 use warnings;
  4         8  
  4         109  
31 4     4   101 use 5.010;
  4         14  
32 4     4   25 use Carp;
  4         8  
  4         332  
33 4     4   27 use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
  4         8  
  4         1450  
34              
35             use overload (
36 841     841   55135 '""' => sub { stringify($_[0]) },
37 51 50   51   1049 '0+' => sub { $_[0] >= 0 ? uintify($_[0]) : intify($_[0]) },
38 4     4   30 'bool' => sub { $_[0] != 0 },
39              
40             '<=>' => \&op_spaceship,
41             '==' => \&op_eq,
42              
43             '+' => \&op_add,
44             '-' => \&op_sub,
45              
46             '&' => \&band,
47             '^' => \&bxor,
48             '|' => \&bior,
49              
50             '<<' => \&blshift,
51             '>>' => \&brshift,
52              
53             '%' => \&op_mod,
54 2 50   2   46 '**' => sub { $_[2] ? op_pow($_[1], $_[0]) : op_pow($_[0], $_[1]) },
55 4         83 '*' => \&op_mul,
56             '/' => \&op_div,
57 4     4   5193 );
  4         4287  
58              
59             require Exporter;
60             require DynaLoader;
61             require AutoLoader;
62              
63             @ISA = qw(Exporter DynaLoader);
64             # Items to export into callers namespace by default. Note: do not export
65             # names by default without a very good reason. Use EXPORT_OK instead.
66             # Do not simply export all your public functions/methods/constants.
67              
68             our $VERSION = '2.23';
69              
70              
71             bootstrap Math::GMP $VERSION;
72              
73 4     4   1105 use strict;
  4         7  
  4         1319  
74             sub import {
75 4     4   41 shift;
76 4 100       4515 return unless @_;
77 1 50 33     10 die "unknown import: @_" unless @_ == 1 and $_[0] eq ':constant';
78 1     2   12 overload::constant integer => sub { Math::GMP->new(shift) };
  2         9  
79 1         60 return;
80             }
81              
82              
83             sub new {
84 1631     1631 1 828231 my $class = shift;
85 1631   100     3963 my $ival = shift || 0;
86 1631         2174 my $base = shift;
87              
88 1631         4377 $ival =~ s/\A\+//;
89 1631         2987 $ival =~ tr/ _//d;
90 1631 100       3085 if ($base) {
91 2         36 return Math::GMP::new_from_scalar_with_base($ival, $base);
92             }
93             else {
94 1629 100       4120 if ($ival =~ /[^\d\-xA-Fa-f]/)
95             {
96 1         11 die "Argument to Math::GMP->new is not a string representing an integer";
97             }
98 1628         23993 return Math::GMP::new_from_scalar($ival);
99             }
100             }
101              
102             BEGIN
103             {
104 4     4   42 *DESTROY = \&Math::GMP::destroy;
105 4         14 *gcd = \&bgcd;
106 4         133 *lcm = \&blcm;
107             }
108              
109             __END__