blib/lib/Number/Latin.pm

filter: Statementstmt 100% 37 / 37 Branchbran 67.8% 19 / 28 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 84.7% 72 / 85 CC 17 SCAR 14.3
CC
17
Cov
84%
latin2int
6.8
int2latin
4.1
int2Latin
4.1
CRAP 4.2
↑ Summary
1  
2 1 require 5;
3 package Number::Latin;
4 1 $VERSION = '1.01'; # Time-stamp: "2001-02-22 16:43:53 MST"
5 1 @ISA = ('Exporter');
6 1 @EXPORT = ('int2latin', 'int2Latin', 'int2LATIN', 'latin2int');
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 require Exporter;
10  
11 #---------------------------------------------------------------------------
12 60 ▶sub int2latin ($) {
Subroutine int2latin: called CC=4 SCAR=14.2
Pod documented
13 60 ▶ return undef unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 60 60
14 60 ▶ return '0' if $_[0] == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] == 0 0 60 60
15 60 ▶ return '-' . _i2l( abs int $_[0] ) if $_[0] <= -1;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] <= -1 30 30 60
16 30 return _i2l( int $_[0] );
17 }
18  
19 2 ▶sub int2Latin ($) {
Subroutine int2Latin: called CC=4 SCAR=14.2
Pod documented
20 # just the above plus ucfirst
21 2 ▶ return undef unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 2 2
22 2 ▶ return '0' if $_[0] == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] == 0 0 2 2
23 2 ▶ return '-' . ucfirst(_i2l( abs int $_[0] )) if $_[0] <= -1;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] <= -1 1 1 2
24 1 return ucfirst(_i2l( int $_[0] ));
25 }
26  
27 2 ▶sub int2LATIN ($) {
Subroutine int2LATIN: called CC=4 SCAR=14.2
Pod documented
28 # just the above plus uc
29 2 ▶ return undef unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 2 2
30 2 ▶ return '0' if $_[0] == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] == 0 0 2 2
31 2 ▶ return '-' . uc(_i2l( abs int $_[0] )) if $_[0] <= -1;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] <= -1 1 1 2
32 1 return uc(_i2l( int $_[0] ));
33 }
34  
35 {
36 1 my @alpha = ('a' .. 'z');
37  
38 208 ▶ sub _i2l { # the real work
Subroutine _i2l: called CC=2 SCAR=6.9
39 208 ▶ my $int = shift(@_) || return "";
Condition100%2/2
shift @_ || (return '')
l!l
14464
MC/DC100%1/1
shift @_ || (return '')
shift @_
Truth table100%2/2
A
A= shift @_
Aresult
11
00
40 144 _i2l(int (($int - 1) / 26)) . $alpha[$int % 26 - 1]; # yes, recursive
41 }
42 }
43  
44 #---------------------------------------------------------------------------
45 1 sub latin2int ($);
46 96 ▶sub latin2int ($) {
Subroutine latin2int: called CC=6 SCAR=19.1
Pod documented
47 96 ▶ return undef unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 96 96
48 96 ▶ return 0 if $_[0] eq '0' or $_[0] =~ m/^0+$/s; # special case
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq 0 or $_[0] =~ /^0+$/s 0 96 96
Condition33%1/3
$_[0] eq 0 or $_[0] =~ /^0+$/s
l!l&&r!l&&!r
0096
MC/DC0%0/2
$_[0] eq 0 or $_[0] =~ /^0+$/s
$_[0] eq 0 $_[0] =~ /^0+$/s
Truth table33%1/3
A or B
A= $_[0] eq 0B= $_[0] =~ /^0+$/s
ABresult
1X1
011
000
49 96 my $in = $_[0];
50 96 ▶ return scalar(-latin2int($1)) if $in =~ m<^-([a-zA-Z]+)$>s;
Branch: 1 branch
BranchTrueFalseTotal
if $in =~ /^-([a-zA-Z]+)$/s 32 64 96
51 64 ▶ return undef unless $_[0] =~ m<^[a-zA-Z]+$>s;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[a-zA-Z]+$/s 0 64 64
52 64 $in =~ tr/A-Z/a-z/;
53 64 _l2i($in);
54 }
55  
56 # use Number::Latin; print ">\n"; print latin2int('aaa'), "\n";
57  
58 144 ▶sub _l2i { # the real work. DESTRUCTIVE to $_[0]
Subroutine _l2i: called CC=2 SCAR=6.9
59 #print "<$_[0]> => ";
60 144 my $sval = ord(
61 # my $x =
62 chop($_[0])
63 ) - ord('a') + 1;
64 #print "sval: $x=>$sval leaving <$_[0]>\n";
65 144 ▶ (length $_[0]) ? ($sval + 26 * _l2i($_[0])) : $sval; # yes, recursive
Branch: 1 branch
BranchTrueFalseTotal
length $_[0] ? : 80 64 144
66 }
67  
68 #---------------------------------------------------------------------------
69 1 1;
70  
71 __END__
↑ Summary