CEGH/Gematria.pm

filter: Statementstmt 95.0% 58 / 61 Branchbran 75.0% 12 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 1 totaltotal 90.9% 80 / 88 CC 12 SCAR 13.0
CC
12
Cov
91%
_simplify
6.4
enumerate
4.0
_index
4.0
CRAP 3.7
« CEGH/Transliterate.pm ↑ Summary CEGH.pm »
1 package Convert::CEGH::Gematria;
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Regexp::Ethiopic qw(:forms setForm);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 BEGIN
8 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use vars qw( $አበገደ $ሀለሐመ $תיבפלא $ΑΛΦΑΒΕΤ %Gematria @EXPORT_OK $VERSION $use_halehame );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 1 @EXPORT_OK = qw( enumerate );
14  
15 1 $VERSION = "0.07";
16  
17 #
18 # Gematria Data:
19 #
20 1 $አበገደ = "አበገደሀወዘሐጠየከለመነሠዐፈጸቀረሰተኀፀጰፐኈ"; # ቈ 1,000 እ 10,000
21 1 $תיבפלא = "אבגדהוזחטיכלמנסעפצקרשתךםןףץ";
22 1 $ΑΛΦΑΒΕΤ = "ΑΒΓΔΕϚΖΗΘΙΚΛΜΝΞΟΠϘΡΣΤΥΦΧΨΩϠ"; # Ϛ/Ϝ
23 1 $ሀለሐመ = "ሀለሐመሠረሰቀበተኀነአከወዐዘየደገጠጰጸፀፈፐ";
24 # $Coptic ="ΑΒΓΔΕϚΖΗϴΙΚΛΜΝΞΟΠ ΡCΤΥΦΧΨΩϢϤϦϨϪϬϮ";
25  
26 1 %Gematria =(
27 eth => $አበገደ,
28 heb => $תיבפלא,
29 ell => $ΑΛΦΑΒΕΤ,
30 et => $አበገደ,
31 he => $תיבפלא,
32 el => $ΑΛΦΑΒΕΤ,
33 et_halehame => $ሀለሐመ
34 );
35  
36 1 $use_halehame = 0;
37 }
38  
39  
40 #
41 # unfortunately the index function in Perl 5.8.0 is broken for some
42 # Unicode sequences: http://rt.perl.org/rt2/Ticket/Display.html?id=22375
43 #
44 sub _index
45 10 ▶{
Subroutine _index: called CC=4 SCAR=13.9
46 10 my ( $haystack, $needle ) = @_;
47  
48 10 my $pos = my $found = 0;
49 10 foreach (split (//, $haystack) ) {
50 270 ▶ $found = 1 if ( /$needle/ );
Branch: 1 branch
BranchTrueFalseTotal
if /$needle/ 10 260 270
51 270 ▶ $pos++ unless ( $found );
Branch: 1 branch
BranchTrueFalseTotal
unless $found 45 225 270
52 }
53  
54 10 $pos;
55 }
56  
57  
58 sub _simplify
59 3 ▶{
Subroutine _simplify: called CC=6 SCAR=18.6
60 3 my ($string) = @_;
61  
62 #
63 # Allow mixed language Gematria:
64 #
65 3 ▶ if ( $string =~ /[$תיבפלא]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /[$Convert::CEGH::Gematria::תיבפלא]/) 1 2 3
66 #
67 # Remove what we don't know.
68 # This also strips vowel markers
69 #
70 1 $string =~ s/[^$תיבפלא]//og;
71 1 return ( $string, "heb" );
72 }
73 2 ▶ if ( $string =~ /[$ΑΛΦΑΒΕΤ]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /[$Convert::CEGH::Gematria::ΑΛΦΑΒΕΤ]/) 1 1 2
74 #
75 # this probably doesn't work, test it
76 # and replace with a tr later if it fails:
77 #
78 1 $string = uc($string);
79 1 $string =~ s/Ϝ/Ϛ/g;
80 1 $string =~ s/Ϟ/Ϙ/g;
81 1 return ( $string, "ell" );
82 }
83 1 ▶ if ( $string =~ /\p{Ethiopic}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /\p{Ethiopic}/) 1 0 1
84 1 ▶ $string =~ s/(.)/($1 eq "ኈ" ) ? "ኈ" : setForm($1,$ግዕዝ)/eg;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq "\x{1288}" ? : 0 3 3
85 1 ▶ if ( $use_halehame ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Convert::CEGH::Gematria::use_halehame) { } 0 1 1
86 0 $string =~ s/(ኈ)/setForm($1,$ግዕዝ)/eg;
87 0 return ( $string, "et_halehame" );
88 }
89 else {
90 1 return ( $string, "eth" );
91 }
92 }
93  
94 }
95  
96  
97 sub enumerate
98 3 ▶{
Subroutine enumerate: called CC=4 SCAR=13.9
Pod undocumented
99 3 my ( @strings ) = @_;
100  
101 3 my ( @sums ) = ();
102 3 foreach ( @strings ) {
103 3 my ($string, $from) = _simplify ( $_ );
104  
105 3 my @letters = split ( //, $string );
106  
107 3 my $sum = 0;
108 3 foreach my $letter (@letters) {
109 10 my $pos = _index ( $Gematria{$from}, $letter );
110 # my $value = (1+(int $pos/10)+$pos%10)*10**(int $pos/10);
111 # my $exp = int $pos/10;
112 # my $power = 10**$exp;
113 # print "$letter => $pos / $exp / $power / $value\n";
114 10 $sum += (1+(int $pos/10)+$pos%10)*10**(int $pos/10);
115 }
116  
117 3 push ( @sums, $sum );
118 }
119  
120 3 ▶ ( wantarray ) ? @sums : $sums[0] ;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
121 }
122  
123  
124 #########################################################
125 # Do not change this, Do not put anything below this.
126 # File must return "true" value at termination
127 1 1;
128 ##########################################################
129  
130 __END__
« CEGH/Transliterate.pm ↑ Summary CEGH.pm »