| 1 | package Convert::Number::Coptic; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use utf8; # can't find a way to conditionally load this with | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | # the scope applying throughout | ||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | BEGIN | ||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use vars qw($VERSION @CNumbers %CNumbers); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | 1 | $VERSION = "0.15"; | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | 1 | require 5.000; | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | 1 | @CNumbers =( | |||||||||||||||||||||||||||||
| 17 | ["α", "β", "γ", "δ", "ε", "ϛ", "ζ", "η", "θ"], | ||||||||||||||||||||||||||||||
| 18 | ["ι", "κ", "λ", "μ", "ν", "ξ", "ο", "π", "ϥ"], | ||||||||||||||||||||||||||||||
| 19 | ["ρ", "ϲ", "τ", "υ", "φ", "χ", "ψ", "ω", "ϣ"] | ||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||
| 21 | 1 | %CNumbers =( | |||||||||||||||||||||||||||||
| 22 | 'α' => 1, | ||||||||||||||||||||||||||||||
| 23 | 'β' => 2, | ||||||||||||||||||||||||||||||
| 24 | 'γ' => 3, | ||||||||||||||||||||||||||||||
| 25 | 'δ' => 4, | ||||||||||||||||||||||||||||||
| 26 | 'ε' => 5, | ||||||||||||||||||||||||||||||
| 27 | 'ϛ' => 6, | ||||||||||||||||||||||||||||||
| 28 | 'ζ' => 7, | ||||||||||||||||||||||||||||||
| 29 | 'η' => 8, | ||||||||||||||||||||||||||||||
| 30 | 'θ' => 9, | ||||||||||||||||||||||||||||||
| 31 | 'ι' => 10, | ||||||||||||||||||||||||||||||
| 32 | 'κ' => 20, | ||||||||||||||||||||||||||||||
| 33 | 'λ' => 30, | ||||||||||||||||||||||||||||||
| 34 | 'μ' => 40, | ||||||||||||||||||||||||||||||
| 35 | 'ν' => 50, | ||||||||||||||||||||||||||||||
| 36 | 'ξ' => 60, | ||||||||||||||||||||||||||||||
| 37 | 'ο' => 70, | ||||||||||||||||||||||||||||||
| 38 | 'π' => 80, | ||||||||||||||||||||||||||||||
| 39 | 'ϥ' => 90, | ||||||||||||||||||||||||||||||
| 40 | 'ρ' => 100, | ||||||||||||||||||||||||||||||
| 41 | 'ϲ' => 200, | ||||||||||||||||||||||||||||||
| 42 | 'τ' => 300, | ||||||||||||||||||||||||||||||
| 43 | 'υ' => 400, | ||||||||||||||||||||||||||||||
| 44 | 'φ' => 500, | ||||||||||||||||||||||||||||||
| 45 | 'χ' => 600, | ||||||||||||||||||||||||||||||
| 46 | 'ψ' => 700, | ||||||||||||||||||||||||||||||
| 47 | 'ω' => 800, | ||||||||||||||||||||||||||||||
| 48 | 'ϣ' => 900 | ||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | sub _setArgs | ||||||||||||||||||||||||||||||
| 55 | 190 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_setArgs: called CC=4 SCAR=16.3
| |||||||||||||||||||||||||||||||
| 56 | 190 | my $self = shift; | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | 190 | ▶ | if ( $#_ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 59 | 0 | warn ( "too many arguments." ); | |||||||||||||||||||||||||||||
| 60 | 0 | return; | |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||
| 62 | 190 | my $number = shift; | |||||||||||||||||||||||||||||
| 63 | 190 | ▶ | unless ( ($number =~ /^\d+$/) || ($number =~ /([α-ρς-ωϛϲ])/) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$number =~ /^\d+$/ or $number =~ /([\x{3b1}-\x{3c1}\x{3c2}-\x{3c9}\x{3db}\x{3f2}])/
MC/DC0%0/2
$number =~ /^\d+$/ or $number =~ /([\x{3b1}-\x{3c1}\x{3c2}-\x{3c9}\x{3db}\x{3f2}])/
$number =~ /^\d+$/
$number =~ /([\x{3b1}-\x{3c1}\x{3c2}-\x{3c9}\x{3db}\x{3f2}])/
Truth table66%2/3
A or B
A= $number =~ /^\d+$/B= $number =~ /([\x{3b1}-\x{3c1}\x{3c2}-\x{3c9}\x{3db}\x{3f2}])/
| |||||||||||||||||||||||||||||||
| 64 | 0 | warn ( "$number is not a number." ); | |||||||||||||||||||||||||||||
| 65 | 0 | return; | |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||
| 68 | 190 | $self->{number} = $number; | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | 190 | 1; | |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||
| 74 | sub new | ||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 76 | 1 | my $class = shift; | |||||||||||||||||||||||||||||
| 77 | 1 | my $self = {}; | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | 1 | my $blessing = bless ( $self, $class ); | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||
| 81 | 1 | $self->{number} = undef; | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | $self->_setArgs ( @_ ) || return if ( @_ ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
@_ && ($self->_setArgs(@_) || (return))
$self->_setArgs(@_) or return
MC/DC0%0/2
@_ && ($self->_setArgs(@_) || (return))
@_
$self->_setArgs(@_)
Truth table33%1/3
A && B
A= @_B= $self->_setArgs(@_)
| |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||
| 85 | 1 | $blessing; | |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||
| 89 | sub _fromCoptic | ||||||||||||||||||||||||||||||
| 90 | 95 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_fromCoptic: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 91 | 95 | $_ = $_[0]->{number}; | |||||||||||||||||||||||||||||
| 92 | 95 | s/̄//og; | |||||||||||||||||||||||||||||
| 93 | 95 | s/̱/000/og; | |||||||||||||||||||||||||||||
| 94 | 95 | s/͇/000000/og; | |||||||||||||||||||||||||||||
| 95 | 95 | s/([α-ρς-ωϛϲ])/$CNumbers{$1}/og; | |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||
| 97 | 95 | my $out = 0; | |||||||||||||||||||||||||||||
| 98 | 95 | s/(\d0+)/$out += $1/oge; | |||||||||||||||||||||||||||||
| 99 | 95 | s/(\d)$/$out += $1/oe; | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | 95 | $out; | |||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||
| 105 | sub toCoptic | ||||||||||||||||||||||||||||||
| 106 | 95 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
toCoptic: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 107 | 95 | my $number = $_[0]->{number}; | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||
| 109 | 95 | my $n = length ( $number ) - 1; | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | # map and return a single digit number | ||||||||||||||||||||||||||||||
| 112 | # don't waste time with the loop: | ||||||||||||||||||||||||||||||
| 113 | 95 | ▶ | return ( "$CNumbers[0][$number-1]̄" ) unless ( $n ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||
| 116 | 91 | my @aNumberString = split ( //, $number ); | |||||||||||||||||||||||||||||
| 117 | 91 | my $cNumberString = ""; | |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||
| 120 | # | ||||||||||||||||||||||||||||||
| 121 | # read number from most to least significant digits: | ||||||||||||||||||||||||||||||
| 122 | # | ||||||||||||||||||||||||||||||
| 123 | 91 | ▶ | for ( my $place = $n; $place >= 0; $place-- ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||
| 125 | 582 | my $pos = $place % 3; | |||||||||||||||||||||||||||||
| 126 | 582 | my $cycles = int $place / 3; | |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||
| 128 | 582 | my $aNum = $aNumberString[$n-$place]; | |||||||||||||||||||||||||||||
| 129 | 582 | ▶ | next unless ( $aNum ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 130 | 305 | $cNumberString .= $CNumbers[$pos][$aNum-1]; | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | 305 | ▶ | if ( $cycles ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 133 | # | ||||||||||||||||||||||||||||||
| 134 | # add an even number of = symbols | ||||||||||||||||||||||||||||||
| 135 | # | ||||||||||||||||||||||||||||||
| 136 | 171 | ▶ | for ( my $i = 0; $i<(int $cycles/2); $i++ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 137 | 75 | $cNumberString .= "͇"; | |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||
| 139 | 171 | ▶ | $cNumberString .= "̱" if ( $cycles % 2 ); # if odd | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||
| 141 | else { | ||||||||||||||||||||||||||||||
| 142 | 134 | $cNumberString .= "̄"; | |||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||
| 147 | 91 | $cNumberString; | |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||
| 151 | sub convert | ||||||||||||||||||||||||||||||
| 152 | 190 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
convert: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 153 | 190 | my $self = shift; | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||
| 155 | # | ||||||||||||||||||||||||||||||
| 156 | # reset string if we've been passed one: | ||||||||||||||||||||||||||||||
| 157 | # | ||||||||||||||||||||||||||||||
| 158 | 190 | ▶ | $self->number ( @_ ) if ( @_ ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||
| 160 | 190 | ▶ | ( $self->number =~ /^[0-9]+$/ ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 161 | ? $self->toCoptic | ||||||||||||||||||||||||||||||
| 162 | : $self->_fromCoptic | ||||||||||||||||||||||||||||||
| 163 | ; | ||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||
| 167 | sub number | ||||||||||||||||||||||||||||||
| 168 | 380 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
number: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 169 | 380 | my $self = shift; | |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||
| 171 | 380 | ▶ | $self->_setArgs ( @_ ) || return | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
@_ && ($self->_setArgs(@_) || (return))
$self->_setArgs(@_) or return
MC/DC0%0/2
@_ && ($self->_setArgs(@_) || (return))
@_
$self->_setArgs(@_)
Truth table33%1/3
A && B
A= @_B= $self->_setArgs(@_)
| |||||||||||||||||||||||||||||||
| 172 | if ( @_ ); | ||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||
| 174 | 380 | $self->{number}; | |||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||
| 178 | ######################################################### | ||||||||||||||||||||||||||||||
| 179 | # Do not change this, Do not put anything below this. | ||||||||||||||||||||||||||||||
| 180 | # File must return "true" value at termination | ||||||||||||||||||||||||||||||
| 181 | 1 | 1; | |||||||||||||||||||||||||||||
| 182 | ########################################################## | ||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||
| 185 | __END__ | ||||||||||||||||||||||||||||||