File Coverage

blib/lib/Math/Int64.pm
Criterion Covered Total %
statement 40 43 93.0
branch 6 8 75.0
condition 5 9 55.5
subroutine 11 11 100.0
pod n/a
total 62 71 87.3


line stmt bran cond sub pod time code
1             package Math::Int64;
2              
3 9     9   692888 use strict;
  9         19  
  9         336  
4 9     9   84 use warnings;
  9         18  
  9         832  
5              
6             BEGIN {
7 9     9   29 our $VERSION = '0.57';
8              
9 9         39 require XSLoader;
10 9         7515 XSLoader::load('Math::Int64', $VERSION);
11             }
12              
13 9     9   71 use warnings::register;
  9         29  
  9         745  
14              
15 9     9   52 use constant MAX_INT64 => string_to_int64 ( '0x7fff_ffff_ffff_ffff');
  9         12  
  9         1264  
16 9     9   66 use constant MIN_INT64 => string_to_int64 ('-0x8000_0000_0000_0000');
  9         33  
  9         571  
17 9     9   49 use constant MAX_UINT64 => string_to_uint64( '0xffff_ffff_ffff_ffff');
  9         15  
  9         5479  
18              
19             require Exporter;
20             our @ISA = qw(Exporter);
21             our @EXPORT_OK = qw(int64
22             int64_to_number
23             net_to_int64 int64_to_net
24             le_to_int64 int64_to_le
25             native_to_int64 int64_to_native
26             string_to_int64 hex_to_int64
27             BER_to_int64 int64_to_BER
28             int64_to_string int64_to_hex
29             int64_rand
30             int64_srand
31             uint64
32             uint64_to_number
33             net_to_uint64 uint64_to_net
34             le_to_uint64 uint64_to_le
35             native_to_uint64 uint64_to_native
36             string_to_uint64 hex_to_uint64
37             BER_to_uint64 uint64_to_BER
38             uint64_to_string uint64_to_hex
39             uint64_rand
40             BER_length
41             MAX_INT64 MIN_INT64 MAX_UINT64
42             );
43              
44             my %available_pragmas = map { $_ => 1 } qw(native_if_available
45             die_on_overflow);
46              
47             sub import {
48 9     9   88 my $pkg = shift;
49 9         25 my (%pragmas, @subs, %native);
50 9         28 for (@_) {
51 59 100 66     206 if ($_ =~ /^:(.*)/ and $available_pragmas{$1}) {
52 2         6 $pragmas{$1} = 1
53             }
54             else {
55 57         116 push @subs, $_;
56             }
57             }
58              
59 9 50       32 if ($pragmas{die_on_overflow}) {
60 0         0 require Math::Int64::die_on_overflow;
61 0         0 Math::Int64::die_on_overflow->import;
62             }
63              
64 9 100       24 if ($pragmas{native_if_available}) {
65 2         958 require Math::Int64::native_if_available;
66 2         15 Math::Int64::native_if_available->import;
67             }
68              
69 9         15992 Math::Int64->export_to_level(1, $pkg, @subs);
70             }
71              
72             sub _check_pragma_compatibility {
73 3 50 66 3   22 if ($^H{'Math::Int64::native_if_available'} and
      33        
74             $^H{'Math::Int64::die_on_overflow'} and
75             warnings::enabled()) {
76 0         0 warnings::warn("Math::Int64::die_on_overflow pragma is useless when Math::Int64::native_if_available is also active");
77             }
78 3         2055 1;
79             }
80              
81 9         120 use overload ( '+' => \&_add,
82             '+=' => \&_add,
83             '-' => \&_sub,
84             '-=' => \&_sub,
85             '*' => \&_mul,
86             '*=' => \&_mul,
87             '**' => \&_pow,
88             '**=' => \&_pow,
89             '/' => \&_div,
90             '/=' => \&_div,
91             '%' => \&_rest,
92             '%=' => \&_rest,
93             'neg' => \&_neg,
94             '++' => \&_inc,
95             '--' => \&_dec,
96             '!' => \&_not,
97             '~' => \&_bnot,
98             '&' => \&_and,
99             '|' => \&_or,
100             '^' => \&_xor,
101             '<<' => \&_left,
102             '>>' => \&_right,
103             '<=>' => \&_spaceship,
104             '>' => \&_gtn,
105             '<' => \&_ltn,
106             '>=' => \&_gen,
107             '<=' => \&_len,
108             '==' => \&_eqn,
109             '!=' => \&_nen,
110             'bool' => \&_bool,
111             '0+' => \&_number,
112             '""' => \&_string,
113             '=' => \&_clone,
114 9     9   6017 fallback => 1 );
  9         22991  
115              
116             package # hide from PAUSE since it also has its own .pm file
117             Math::UInt64;
118 9         87 use overload ( '+' => \&_add,
119             '+=' => \&_add,
120             '-' => \&_sub,
121             '-=' => \&_sub,
122             '*' => \&_mul,
123             '*=' => \&_mul,
124             '**' => \&_pow,
125             '**=' => \&_pow,
126             '/' => \&_div,
127             '/=' => \&_div,
128             '%' => \&_rest,
129             '%=' => \&_rest,
130             'neg' => \&_neg,
131             '++' => \&_inc,
132             '--' => \&_dec,
133             '!' => \&_not,
134             '~' => \&_bnot,
135             '&' => \&_and,
136             '|' => \&_or,
137             '^' => \&_xor,
138             '<<' => \&_left,
139             '>>' => \&_right,
140             '<=>' => \&_spaceship,
141             '>' => \&_gtn,
142             '<' => \&_ltn,
143             '>=' => \&_gen,
144             '<=' => \&_len,
145             '==' => \&_eqn,
146             '!=' => \&_nen,
147             'bool' => \&_bool,
148             '0+' => \&_number,
149             '""' => \&_string,
150             '=' => \&_clone,
151 9     9   5334 fallback => 1 );
  9         13  
152              
153             1;
154              
155             # ABSTRACT: Manipulate 64 bits integers in Perl
156              
157             __END__