File Coverage

blib/lib/Math/GMP.pm
Criterion Covered Total %
statement 40 40 100.0
branch 8 10 80.0
condition 3 5 60.0
subroutine 12 12 100.0
pod 1 1 100.0
total 64 68 94.1


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   265093 use strict;
  4         37  
  4         95  
30 4     4   19 use warnings;
  4         7  
  4         74  
31 4     4   90 use 5.010;
  4         12  
32 4     4   16 use Carp;
  4         5  
  4         303  
33 4     4   25 use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
  4         5  
  4         918  
34              
35             use overload (
36             '""' => \&op_stringify,
37             '0+' => \&op_numify,
38             'bool' => \&op_bool,
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   1402 '**' => sub { $_[2] ? op_pow($_[1], $_[0]) : op_pow($_[0], $_[1]) },
55 4         69 '*' => \&op_mul,
56             '/' => \&op_div,
57 4     4   3975 );
  4         3480  
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.25';
69              
70              
71             bootstrap Math::GMP $VERSION;
72              
73 4     4   886 use strict;
  4         6  
  4         1026  
74             sub import {
75 4     4   27 shift;
76 4 100       3680 return unless @_;
77 1 50 33     8 die "unknown import: @_" unless @_ == 1 and $_[0] eq ':constant';
78 1     2   5 overload::constant integer => sub { Math::GMP->new(shift) };
  2         5  
79 1         33 return;
80             }
81              
82              
83             sub new {
84 1639     1639 1 715470 my $class = shift;
85 1639   100     3233 my $ival = shift || 0;
86 1639         1751 my $base = shift;
87              
88 1639         3385 $ival =~ s/\A\+//;
89 1639         2359 $ival =~ tr/ _//d;
90 1639 100       2516 if ($base) {
91 2         29 return Math::GMP::new_from_scalar_with_base($ival, $base);
92             }
93             else {
94 1637 100       3462 if ($ival =~ /[^\d\-xA-Fa-f]/)
95             {
96 1         8 die "Argument to Math::GMP->new is not a string representing an integer";
97             }
98 1636         19457 return Math::GMP::new_from_scalar($ival);
99             }
100             }
101              
102             BEGIN
103             {
104 4     4   19 *DESTROY = \&Math::GMP::destroy;
105 4         10 *gcd = \&bgcd;
106 4         122 *lcm = \&blcm;
107             }
108              
109             __END__