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   334872 use strict;
  4         50  
  4         191  
30 4     4   24 use warnings;
  4         11  
  4         133  
31 4     4   136 use 5.010;
  4         14  
32 4     4   28 use Carp;
  4         8  
  4         334  
33 4     4   29 use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
  4         6  
  4         1480  
34              
35             use overload (
36 845     845   53399 '""' => sub { stringify($_[0]) },
37 59 50   59   1136 '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   64 '**' => sub { $_[2] ? op_pow($_[1], $_[0]) : op_pow($_[0], $_[1]) },
55 4         77 '*' => \&op_mul,
56             '/' => \&op_div,
57 4     4   5244 );
  4         4311  
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.24';
69              
70              
71             bootstrap Math::GMP $VERSION;
72              
73 4     4   1217 use strict;
  4         10  
  4         1333  
74             sub import {
75 4     4   41 shift;
76 4 100       4233 return unless @_;
77 1 50 33     12 die "unknown import: @_" unless @_ == 1 and $_[0] eq ':constant';
78 1     2   8 overload::constant integer => sub { Math::GMP->new(shift) };
  2         19  
79 1         50 return;
80             }
81              
82              
83             sub new {
84 1639     1639 1 807429 my $class = shift;
85 1639   100     3814 my $ival = shift || 0;
86 1639         2456 my $base = shift;
87              
88 1639         4221 $ival =~ s/\A\+//;
89 1639         2871 $ival =~ tr/ _//d;
90 1639 100       2995 if ($base) {
91 2         34 return Math::GMP::new_from_scalar_with_base($ival, $base);
92             }
93             else {
94 1637 100       4277 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 1636         23214 return Math::GMP::new_from_scalar($ival);
99             }
100             }
101              
102             BEGIN
103             {
104 4     4   52 *DESTROY = \&Math::GMP::destroy;
105 4         15 *gcd = \&bgcd;
106 4         149 *lcm = \&blcm;
107             }
108              
109             __END__