line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Prime::XS; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
45139
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
150
|
|
4
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
127
|
|
5
|
4
|
|
|
4
|
|
23
|
use base qw(Exporter); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
410
|
|
6
|
4
|
|
|
4
|
|
2302
|
use boolean qw(true false); |
|
4
|
|
|
|
|
9873
|
|
|
4
|
|
|
|
|
22
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
387
|
use Carp qw(croak); |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
275
|
|
9
|
4
|
|
|
4
|
|
3735
|
use Params::Validate ':all'; |
|
4
|
|
|
|
|
56341
|
|
|
4
|
|
|
|
|
1093
|
|
10
|
4
|
|
|
4
|
|
41
|
use Scalar::Util qw(looks_like_number); |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
2746
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our ($VERSION, @EXPORT_OK, %EXPORT_TAGS); |
13
|
|
|
|
|
|
|
my @subs; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$VERSION = '0.26'; |
16
|
|
|
|
|
|
|
@subs = qw(is_prime primes mod_primes sieve_primes sum_primes trial_primes); |
17
|
|
|
|
|
|
|
@EXPORT_OK = @subs; |
18
|
|
|
|
|
|
|
%EXPORT_TAGS = ('all' => [ @subs ]); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
validation_options( |
21
|
|
|
|
|
|
|
on_fail => sub |
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
my ($error) = @_; |
24
|
|
|
|
|
|
|
chomp $error; |
25
|
|
|
|
|
|
|
croak $error; |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
stack_skip => 2, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
*primes = \&sieve_primes; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Reverse arguments for xs_*_primes() when both base and number are specified |
33
|
5
|
100
|
|
5
|
1
|
152761
|
sub mod_primes { _validate(@_); @_ == 1 ? xs_mod_primes ($_[0], 2) : xs_mod_primes (reverse @_) } |
|
5
|
|
|
|
|
53
|
|
34
|
8
|
100
|
|
8
|
1
|
21764
|
sub sieve_primes { _validate(@_); @_ == 1 ? xs_sieve_primes($_[0], 2) : xs_sieve_primes(reverse @_) } |
|
8
|
|
|
|
|
43272
|
|
35
|
3
|
100
|
|
3
|
1
|
9
|
sub sum_primes { _validate(@_); @_ == 1 ? xs_sum_primes ($_[0], 2) : xs_sum_primes (reverse @_) } |
|
3
|
|
|
|
|
66
|
|
36
|
3
|
100
|
|
3
|
1
|
10
|
sub trial_primes { _validate(@_); @_ == 1 ? xs_trial_primes($_[0], 2) : xs_trial_primes(reverse @_) } |
|
3
|
|
|
|
|
46
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _validate |
39
|
|
|
|
|
|
|
{ |
40
|
31
|
50
|
|
31
|
|
978
|
my $positive_num = sub { looks_like_number($_[0]) && $_[0] >= 0 }; |
|
19
|
|
|
19
|
|
83
|
|
41
|
|
|
|
|
|
|
|
42
|
19
|
|
|
|
|
133
|
validate_pos(@_, |
43
|
|
|
|
|
|
|
{ type => SCALAR, |
44
|
|
|
|
|
|
|
callbacks => { |
45
|
|
|
|
|
|
|
'is a positive number' => $positive_num, |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
{ type => SCALAR, |
49
|
|
|
|
|
|
|
optional => true, |
50
|
|
|
|
|
|
|
callbacks => { |
51
|
|
|
|
|
|
|
'is a positive number' => $positive_num, |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
); |
55
|
19
|
100
|
|
|
|
164
|
if (@_ == 2) { |
56
|
12
|
|
|
|
|
22
|
my ($base, $number) = @_; |
57
|
12
|
50
|
|
|
|
66
|
croak 'Base is greater than the number' if $base > $number; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
require XSLoader; |
62
|
|
|
|
|
|
|
XSLoader::load(__PACKAGE__, $VERSION); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
__END__ |