blib/lib/Math/Base/Convert/Bases.pm

filter: Statementstmt 87.5% 56 / 64 Branchbran 100% 8 / 8 Conditioncond 81.8% 18 / 22 MC/DCmcdc 60.0% 6 / 10 Subroutinesub 91.6% 22 / 24 Podpod 0.0% 0 / 21 totaltotal 73.8% 110 / 149 SCAR 26.7
CC
14
Cov
87%
hex
7.1
oct
7.1
_bases
6.0
CRAP 14.4
« blib/lib/Math/Base/Convert/CalcPP.pm ↑ Summary blib/lib/Math/Base/Convert/Bitmaps.pm »
1 #!/usr/bin/perl
2  
3 package Math::Base::Convert::Bases;
4  
5 20 $VERSION = 0.03;
6  
7 package Math::Base::Convert; # into the main package
8  
9 20 @BASES = qw( bin dna DNA oct dec hex HEX b62 b64 m64 iru url rex id0 id1 xnt xid b85 ascii );
10  
11 20 $signedBase = 16; # largest allowable known signed base
12  
13 20 my $package = __PACKAGE__;
14 20 my $packageLen = length __PACKAGE__;
15  
16 sub _class {
17 0 ▶ (my $class = (caller(1))[3]) =~ s/([^:]+)$/_bs::$1/;
Subroutine _class: not called CC=1 SCAR=6.9
18 0 $class;
19 }
20  
21 20 my $callname = __PACKAGE__ . '::_bs::';
22  
23 # return a pointer to a sub for the array blessed into Package::sub::name
24 #
25  
26 20 my $_bin = bless ['0', '1'], $callname . 'bin';
27 20 my $_dna = bless [qw( a c t g )], $callname . 'dna';
28 20 my $_DNA = bless [qw( A C T G )], $callname . 'DNA';
29 20 my $_ocT = bless ['0'..'7'], $callname . 'ocT';
30 20 my $_dec = bless ['0'..'9'], $callname . 'dec';
31 20 my $_heX = bless ['0'..'9', 'a'..'f'], $callname . 'heX';
32 20 my $_HEX = bless ['0'..'9', 'A'..'F'], $callname . 'HEX';
33 20 my $_b62 = bless ['0'..'9', 'a'..'z', 'A'..'Z'], $callname . 'b62';
34 20 my $_b64 = bless ['0'..'9', 'A'..'Z', 'a'..'z', '.', '_'], $callname . 'b64';
35 20 my $_m64 = bless ['A'..'Z', 'a'..'z', '0'..'9', '+', '/'], $callname . 'm64';
36 20 my $_iru = bless ['A'..'Z', 'a'..'z', '0'..'9', '[', ']'], $callname . 'iru';
37 20 my $_url = bless ['A'..'Z', 'a'..'z', '0'..'9', '*', '-'], $callname . 'url';
38 20 my $_rex = bless ['A'..'Z', 'a'..'z', '0'..'9', '!', '-'], $callname . 'rex';
39 20 my $_id0 = bless ['A'..'Z', 'a'..'z', '0'..'9', '_', '-'], $callname . 'id0';
40 20 my $_id1 = bless ['A'..'Z', 'a'..'z', '0'..'9', '.', '_'], $callname . 'id1';
41 20 my $_xnt = bless ['A'..'Z', 'a'..'z', '0'..'9', '.', '-'], $callname . 'xnt';
42 20 my $_xid = bless ['A'..'Z', 'a'..'z', '0'..'9', '_', ':'], $callname . 'xid';
43 20 my $_b85 = bless ['0'..'9', 'A'..'Z', 'a'..'z', '!', '#', # RFC 1924 for IPv6 addresses, might need to return Math::BigInt objs
44 '$', '%', '&', '(', ')', '*', '+', '-', ';', '<', '=', '>', '?', '@', '^', '_', '`', '{', '|', '}', '~'], $callname . 'b85';
45  
46 20 my $_ascii = bless [
47 ' ','!','"','#','$','%','&',"'",'(',')','*','+',',','-','.','/',
48 '0','1','2','3','4','5','6','7','8','9',
49 ':',';','<','=','>','?','@',
50 'A','B','C','D','E','F','G','H','I','J','K','L','M',
51 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
52 '[','\\',']','^','_','`',
53 'a','b','c','d','e','f','g','h','i','j','k','l','m',
54 'n','o','p','q','r','s','t','u','v','w','x','y','z',
55 '{','|','}','~'], $callname . 'ascii'; # 7 bit printable ascii, base 96
56  
57 #my $_ebcdic = bless [qw
58 # ( 0 1 2 3 37 2D 2E 2F 16 5 25 0B 0C 0D 0E 0F 10 11 12 13 3C 3D 32 26 18 19 3F 27 1C 1D 1E 1F
59 # 40 4F 7F 7B 5B 6C 50 7D 4D 5D 5C 4E 6B 60 4B 61 F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 7A 5E 4C 7E 6E 6F
60 # 7C C1 C2 C3 C4 C5 C6 C7 C8 C9 D1 D2 D3 D4 D5 D6 D7 D8 D9 E2 E3 E4 E5 E6 E7 E8 E9 4A E0 5A 5F 6D
61 # 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 97 98 99 A2 A3 A4 A5 A6 A7 A8 A9 C0 6A D0 A1 7
62 # 20 21 22 23 24 15 6 17 28 29 2A 2B 2C 9 0A 1B 30 31 1A 33 34 35 36 8 38 39 3A 3B 4 14 3E E1 41
63 # 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57 58 59 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
64 # 77 78 80 8A 8B 8C 8D 8E 8F 90 9A 9B 9C 9D 9E 9F A0 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8
65 # B9 BA BB BC BD BE BF CA CB CC CD CE CF DA DB DC DD DE DF EA EB EC ED EE EF FA FB FC FD FE FF)], $callname . 'ebcdic';
66  
67 845 ▶sub bin { $_bin }
Subroutine bin: called CC=1 SCAR=0.0
Pod undocumented
68 1123 ▶sub dna { $_dna }
Subroutine dna: called CC=1 SCAR=0.0
Pod undocumented
69 1141 ▶sub DNA { $_DNA }
Subroutine DNA: called CC=1 SCAR=0.0
Pod undocumented
70 1065 ▶sub ocT { $_ocT }
Subroutine ocT: called CC=1 SCAR=0.0
Pod undocumented
71 1158 ▶sub dec { $_dec }
Subroutine dec: called CC=1 SCAR=0.0
Pod undocumented
72 1500 ▶sub heX { $_heX }
Subroutine heX: called CC=1 SCAR=0.0
Pod undocumented
73 1064 ▶sub HEX { $_HEX }
Subroutine HEX: called CC=1 SCAR=0.0
Pod undocumented
74 928 ▶sub b62 { $_b62 }
Subroutine b62: called CC=1 SCAR=0.0
Pod undocumented
75 929 ▶sub b64 { $_b64 }
Subroutine b64: called CC=1 SCAR=0.0
Pod undocumented
76 1107 ▶sub m64 { $_m64 }
Subroutine m64: called CC=1 SCAR=0.0
Pod undocumented
77 3 ▶sub iru { $_iru }
Subroutine iru: called CC=1 SCAR=0.0
Pod undocumented
78 3 ▶sub url { $_url }
Subroutine url: called CC=1 SCAR=0.0
Pod undocumented
79 3 ▶sub rex { $_rex }
Subroutine rex: called CC=1 SCAR=0.0
Pod undocumented
80 3 ▶sub id0 { $_id0 }
Subroutine id0: called CC=1 SCAR=0.0
Pod undocumented
81 3 ▶sub id1 { $_id1 }
Subroutine id1: called CC=1 SCAR=0.0
Pod undocumented
82 3 ▶sub xnt { $_xnt }
Subroutine xnt: called CC=1 SCAR=0.0
Pod undocumented
83 3 ▶sub xid { $_xid }
Subroutine xid: called CC=1 SCAR=0.0
Pod undocumented
84 17 ▶sub b85 { $_b85 }
Subroutine b85: called CC=1 SCAR=0.0
Pod undocumented
85 1 ▶sub ascii { $_ascii }
Subroutine ascii: called CC=1 SCAR=0.0
Pod undocumented
86 #sub ebcdic { $_ebcdic }
87  
88 # Since we're not using BIcalc, the last test can be eliminated...
89 ################### special treatment for override 'hex' ##################################
90  
91 sub hex {
92 # unless our package and is a BC ref and not a BI number (which is an ARRAY)
93 1071 ▶ unless (ref($_[0]) && $package eq substr(ref($_[0]),0,$packageLen) && (local *glob = $_[0]) && *glob{HASH}) {
Subroutine hex: called CC=7 SCAR=19.5
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_[0] and $package eq substr(ref $_[0], 0, $packageLen) and local *glob = $_[0] and *glob{"HASH"}) 430 2 432
Condition75%6/8
ref $_[0] and $package eq substr(ref $_[0], 0, $packageLen) and local *glob = $_[0] and *glob{"HASH"}
!ll
639432
ref $_[0] and $package eq substr(ref $_[0], 0, $packageLen) and local *glob = $_[0]
!ll&&!rl&&r
6390432
ref $_[0] and $package eq substr(ref $_[0], 0, $packageLen)
!ll&&!rl&&r
6390432
MC/DC33%1/3
ref $_[0] and $package eq substr(ref $_[0], 0, $packageLen) and local *glob = $_[0] and *glob{"HASH"}
ref $_[0] $package eq substr(ref $_[0], 0, $packageLen) local *glob = $_[0]
Truth table50%2/4
A and B and C
A= ref $_[0]B= $package eq substr(ref $_[0], 0, $packageLen)C= local *glob = $_[0]
ABCresult
0XX0
10X0
1100
1111
94 # $package, $filename, $line, $subroutine, $hasargs
95 # 0 1 2 3 4
96 # if defined and hasargs
97 1069 ▶ if ( defined $_[0] && (caller(0))[4] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and (caller 0)[4]) 4 1065 1069
Condition100%3/3
defined $_[0] and (caller 0)[4]
!ll&&!rl&&r
4276384
MC/DC100%2/2
defined $_[0] and (caller 0)[4]
defined $_[0] (caller 0)[4]
Truth table100%3/3
A and B
A= defined $_[0]B= (caller 0)[4]
ABresult
0X0
100
111
98 4 return CORE::hex $_[0];
99 }
100 }
101 1067 return heX();
102 }
103  
104 ################### special treatment for override 'oct' #################################
105 sub oct {
106 # unless our package and is a BC ref and not a BI number (which is an ARRAY)
107 835 ▶ unless (ref($_[0]) && $package eq substr(ref($_[0]),0,$packageLen) && (local *glob = $_[0]) && *glob{HASH}) {
Subroutine oct: called CC=7 SCAR=19.5
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_[0] and $package eq substr(ref $_[0], 0, $packageLen) and local *glob = $_[0] and *glob{"HASH"}) 210 2 212
Condition75%6/8
ref $_[0] and $package eq substr(ref $_[0], 0, $packageLen) and local *glob = $_[0] and *glob{"HASH"}
!ll
623212
ref $_[0] and $package eq substr(ref $_[0], 0, $packageLen) and local *glob = $_[0]
!ll&&!rl&&r
6230212
ref $_[0] and $package eq substr(ref $_[0], 0, $packageLen)
!ll&&!rl&&r
6230212
MC/DC33%1/3
ref $_[0] and $package eq substr(ref $_[0], 0, $packageLen) and local *glob = $_[0] and *glob{"HASH"}
ref $_[0] $package eq substr(ref $_[0], 0, $packageLen) local *glob = $_[0]
Truth table50%2/4
A and B and C
A= ref $_[0]B= $package eq substr(ref $_[0], 0, $packageLen)C= local *glob = $_[0]
ABCresult
0XX0
10X0
1100
1111
108 # $package, $filename, $line, $subroutine, $hasargs
109 # 0 1 2 3 4
110 # if defined and hasargs
111 833 ▶ if ( defined $_[0] && (caller(0))[4] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and (caller 0)[4]) 4 829 833
Condition100%3/3
defined $_[0] and (caller 0)[4]
!ll&&!rl&&r
4104194
MC/DC100%2/2
defined $_[0] and (caller 0)[4]
defined $_[0] (caller 0)[4]
Truth table100%3/3
A and B
A= defined $_[0]B= (caller 0)[4]
ABresult
0X0
100
111
112 4 return CORE::oct $_[0];
113 }
114 }
115 831 return ocT();
116 }
117  
118 ################################## REMOVE ABOVE CODE ###################
119  
120 # return a hash of all base pointers
121 #
122 sub _bases {
123 20 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 0 ▶ my %bases;
Subroutine _bases: not called CC=2 SCAR=17.9
125 0 foreach (@BASES) {
126 0 my $base = $_->();
127 0 ref($base) =~ /([^:]+)$/;
128 0 $bases{$1} = $base;
129 }
130 0 \%bases;
131 }
132 20 1;
133  
134 __END__
« blib/lib/Math/Base/Convert/CalcPP.pm ↑ Summary blib/lib/Math/Base/Convert/Bitmaps.pm »