blib/lib/Math/NumberBase/XS.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 10 / 10 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 11 / 11 Podpod 100% 8 / 8 totaltotal 100% 77 / 77 CC 8 SCAR 14.1
CC
8
Cov
100%
new
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.1
↑ Summary XS.xs »
1 package Math::NumberBase::XS;
2
3 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 2 require XSLoader;
8 2 our $VERSION = '0.0202';
9
10 2 XSLoader::load('Math::NumberBase::XS', $VERSION);
11
12 15 ▶sub new {
Subroutine new: called CC=8 SCAR=20.8
Pod documented
13 15 my ($class, $base, $symbols) = @_;
14
15 15 ▶ $base //= 10;
Condition100%2/2
$base //= 10
l!l
141
MC/DC100%1/1
$base //= 10
$base
Truth table100%2/2
A
A= $base
Aresult
11
00
16 15 ▶ die '$base must be an integer >= 2' if $base < 2 || int($base) != $base;
Branch: 1 branch
BranchTrueFalseTotal
if $base < 2 or int $base != $base 2 13 15
Condition100%3/3
$base < 2 or int $base != $base
l!l&&r!l&&!r
1113
MC/DC100%2/2
$base < 2 or int $base != $base
$base < 2 int $base != $base
Truth table100%3/3
A or B
A= $base < 2B= int $base != $base
ABresult
1X1
011
000
17
18 my @symbols_array = defined $symbols
19 ? split //, $symbols
20 13 ▶ : do {
Branch: 1 branch
BranchTrueFalseTotal
defined $symbols ? : 10 3 13
21 3 ▶ die 'Cannot auto determine symbols for base > 36' if $base > 36;
Branch: 1 branch
BranchTrueFalseTotal
if $base > 36 1 2 3
22 2 my @numalpha = (0 .. 9, 'a' .. 'z');
23 2 splice @numalpha, 0, $base;
24 };
25
26 12 my %symbol_value_map = map { $symbols_array[$_] => $_ } 0 .. $#symbols_array;
27
28 12 ▶ die 'Symbols length must match base' if @symbols_array != $base;
Branch: 1 branch
BranchTrueFalseTotal
if @symbols_array != $base 1 11 12
29 11 ▶ die 'Symbols contain duplicates' if keys(%symbol_value_map) != @symbols_array;
Branch: 1 branch
BranchTrueFalseTotal
if keys %symbol_value_map != @symbols_array 1 10 11
30
31 10 my $self = bless {}, $class;
32 10 $self->_init($base, \@symbols_array, \%symbol_value_map);
33
34 10 return $self;
35 }
36
37 2 ▶sub get_base {
Subroutine get_base: called CC=1 SCAR=0.0
Pod documented
38 2 my ($self) = @_;
39 2 return $self->_get_base();
40 }
41
42 2 ▶sub get_symbols {
Subroutine get_symbols: called CC=1 SCAR=0.0
Pod documented
43 2 my ($self) = @_;
44 2 return $self->_get_symbols();
45 }
46
47 1 ▶sub get_symbol_value_map {
Subroutine get_symbol_value_map: called CC=1 SCAR=0.0
Pod documented
48 1 my ($self) = @_;
49 1 return $self->_get_symbol_value_map();
50 }
51
52 16 ▶sub to_decimal {
Subroutine to_decimal: called CC=1 SCAR=0.0
Pod documented
53 16 my ($self, $string) = @_;
54 16 return $self->_to_decimal($string);
55 }
56
57 12 ▶sub from_decimal {
Subroutine from_decimal: called CC=1 SCAR=0.0
Pod documented
58 12 my ($self, $in_decimal) = @_;
59 12 return $self->_from_decimal($in_decimal);
60 }
61
62 4 ▶sub convert_to {
Subroutine convert_to: called CC=1 SCAR=0.0
Pod documented
63 4 my ($self, $string, $number_base) = @_;
64 4 return $number_base->from_decimal($self->to_decimal($string));
65 }
66
67 4 ▶sub convert_from {
Subroutine convert_from: called CC=1 SCAR=0.0
Pod documented
68 4 my ($self, $string, $number_base) = @_;
69 4 return $self->from_decimal($number_base->to_decimal($string));
70 }
71
72 2 1;
73
74 __END__
↑ Summary XS.xs »