| 1 | package Math::Prime::XS; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use boolean qw(true false); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | ▶ | use Params::Validate ':all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 4 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 4 | our ($VERSION, @EXPORT_OK, %EXPORT_TAGS); | |||||||||
| 13 | 4 | my @subs; | |||||||||
| 14 | |||||||||||
| 15 | 4 | $VERSION = '0.27'; | |||||||||
| 16 | 4 | @subs = qw(is_prime primes count_primes | |||||||||
| 17 | mod_primes sieve_primes sum_primes trial_primes); | ||||||||||
| 18 | 4 | @EXPORT_OK = @subs; | |||||||||
| 19 | 4 | %EXPORT_TAGS = ('all' => [ @subs ]); | |||||||||
| 20 | |||||||||||
| 21 | validation_options( | ||||||||||
| 22 | on_fail => sub | ||||||||||
| 23 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 24 | 0 | my ($error) = @_; | |||||||||
| 25 | 0 | chomp $error; | |||||||||
| 26 | 0 | croak $error; | |||||||||
| 27 | }, | ||||||||||
| 28 | 4 | stack_skip => 2, | |||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | 4 | *primes = \&sieve_primes; | |||||||||
| 32 | 2 | ▶ | sub count_primes { _validate(@_); @_ == 1 ? xs_sieve_count_primes($_[0], 2) : xs_sieve_count_primes(reverse @_) } | ||||||||
|
Subroutine
count_primes: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 33 | |||||||||||
| 34 | # Reverse arguments for xs_*_primes() when both base and number are specified | ||||||||||
| 35 | 5 | ▶ | sub mod_primes { _validate(@_); @_ == 1 ? xs_mod_primes ($_[0], 2) : xs_mod_primes (reverse @_) } | ||||||||
|
Subroutine
mod_primes: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 36 | 8 | ▶ | sub sieve_primes { _validate(@_); @_ == 1 ? xs_sieve_primes($_[0], 2) : xs_sieve_primes(reverse @_) } | ||||||||
|
Subroutine
sieve_primes: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 37 | 3 | ▶ | sub sum_primes { _validate(@_); @_ == 1 ? xs_sum_primes ($_[0], 2) : xs_sum_primes (reverse @_) } | ||||||||
|
Subroutine
sum_primes: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 38 | 3 | ▶ | sub trial_primes { _validate(@_); @_ == 1 ? xs_trial_primes($_[0], 2) : xs_trial_primes(reverse @_) } | ||||||||
|
Subroutine
trial_primes: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | sub _validate | ||||||||||
| 41 | 21 | ▶ | { | ||||||||
|
Subroutine
_validate: called CC=3 SCAR=11.1
| |||||||||||
| 42 | 21 | ▶ | my $positive_num = sub { looks_like_number($_[0]) && $_[0] >= 0 }; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | 21 | 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 | ▶ | if (@_ == 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 13 | my ($base, $number) = @_; | |||||||||
| 59 | 13 | ▶ | croak 'Base is greater than the number' if $base > $number; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | } | ||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 4 | require XSLoader; | |||||||||
| 64 | 4 | XSLoader::load(__PACKAGE__, $VERSION); | |||||||||
| 65 | |||||||||||
| 66 | 4 | 1; | |||||||||
| 67 | __END__ | ||||||||||