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