File Coverage

blib/lib/Convert/CEGH/Gematria.pm
Criterion Covered Total %
statement 57 60 95.0
branch 12 16 75.0
condition n/a
subroutine 10 10 100.0
pod 0 1 0.0
total 79 87 90.8


line stmt bran cond sub pod time code
1             package Convert::CEGH::Gematria;
2 1     1   92427 use warnings;
  1         1  
  1         44  
3 1     1   4 use strict;
  1         1  
  1         19  
4 1     1   3 use utf8;
  1         1  
  1         4  
5 1     1   476 use Regexp::Ethiopic qw(:forms setForm);
  1         6484  
  1         5  
6              
7             BEGIN
8             {
9 1     1   502 use base qw( Exporter );
  1         3  
  1         114  
10 1     1   5 use vars qw( $አበገደ $ሀለሐመ $תיבפלא $ΑΛΦΑΒΕΤ %Gematria @EXPORT_OK $VERSION $use_halehame );
  1         1  
  1         179  
11              
12              
13 1     1   3 @EXPORT_OK = qw( enumerate );
14              
15 1         2 $VERSION = "0.07";
16              
17             #
18             # Gematria Data:
19             #
20 1         1 $አበገደ = "አበገደሀወዘሐጠየከለመነሠዐፈጸቀረሰተኀፀጰፐኈ"; # ቈ 1,000 እ 10,000
21 1         3 $תיבפלא = "אבגדהוזחטיכלמנסעפצקרשתךםןףץ";
22 1         2 $ΑΛΦΑΒΕΤ = "ΑΒΓΔΕϚΖΗΘΙΚΛΜΝΞΟΠϘΡΣΤΥΦΧΨΩϠ"; # Ϛ/Ϝ
23 1         1 $ሀለሐመ = "ሀለሐመሠረሰቀበተኀነአከወዐዘየደገጠጰጸፀፈፐ";
24             # $Coptic ="ΑΒΓΔΕϚΖΗϴΙΚΛΜΝΞΟΠ ΡCΤΥΦΧΨΩϢϤϦϨϪϬϮ";
25              
26 1         6 %Gematria =(
27             eth => $አበገደ,
28             heb => $תיבפלא,
29             ell => $ΑΛΦΑΒΕΤ,
30             et => $አበገደ,
31             he => $תיבפלא,
32             el => $ΑΛΦΑΒΕΤ,
33             et_halehame => $ሀለሐመ
34             );
35              
36 1         550 $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             {
46 10     10   24 my ( $haystack, $needle ) = @_;
47              
48 10         18 my $pos = my $found = 0;
49 10         60 foreach (split (//, $haystack) ) {
50 270 100       733 $found = 1 if ( /$needle/ );
51 270 100       515 $pos++ unless ( $found );
52             }
53              
54 10         40 $pos;
55             }
56              
57              
58             sub _simplify
59             {
60 3     3   8 my ($string) = @_;
61              
62             #
63             # Allow mixed language Gematria:
64             #
65 3 100       63 if ( $string =~ /[$תיבפלא]/ ) {
66             #
67             # Remove what we don't know.
68             # This also strips vowel markers
69             #
70 1         63 $string =~ s/[^$תיבפלא]//og;
71 1         7 return ( $string, "heb" );
72             }
73 2 100       34 if ( $string =~ /[$ΑΛΦΑΒΕΤ]/ ) {
74             #
75             # this probably doesn't work, test it
76             # and replace with a tr later if it fails:
77             #
78 1         33 $string = uc($string);
79 1         4 $string =~ s/Ϝ/Ϛ/g;
80 1         4 $string =~ s/Ϟ/Ϙ/g;
81 1         5 return ( $string, "ell" );
82             }
83 1 50       9 if ( $string =~ /\p{Ethiopic}/ ) {
84 1 50       7 $string =~ s/(.)/($1 eq "ኈ" ) ? "ኈ" : setForm($1,$ግዕዝ)/eg;
  3         57  
85 1 50       18 if ( $use_halehame ) {
86 0         0 $string =~ s/(ኈ)/setForm($1,$ግዕዝ)/eg;
  0         0  
87 0         0 return ( $string, "et_halehame" );
88             }
89             else {
90 1         5 return ( $string, "eth" );
91             }
92             }
93              
94             }
95              
96              
97             sub enumerate
98             {
99 3     3 0 185506 my ( @strings ) = @_;
100              
101 3         7 my ( @sums ) = ();
102 3         11 foreach ( @strings ) {
103 3         12 my ($string, $from) = _simplify ( $_ );
104              
105 3         14 my @letters = split ( //, $string );
106              
107 3         6 my $sum = 0;
108 3         8 foreach my $letter (@letters) {
109 10         79 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         33 $sum += (1+(int $pos/10)+$pos%10)*10**(int $pos/10);
115             }
116              
117 3         11 push ( @sums, $sum );
118             }
119              
120 3 50       39 ( wantarray ) ? @sums : $sums[0] ;
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;
128             ##########################################################
129              
130             __END__