| 1 | package Lingua::EN::Numbers::Years; | ||||||||||||||||||||||||||||
| 2 | 1 | $Lingua::EN::Numbers::Years::VERSION = '1.05'; | |||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Lingua::EN::Numbers 1.01 qw(num2en); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 10 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | my $T = 'thousand'; | |||||||||||||||||||||||||||
| 13 | 1 | my $H = 'hundred'; | |||||||||||||||||||||||||||
| 14 | 1 | my $Oh = 'oh'; | |||||||||||||||||||||||||||
| 15 | 1 | my $Zero = 'zero'; | |||||||||||||||||||||||||||
| 16 | 1 | my %DD; | |||||||||||||||||||||||||||
| 17 | my %OhDD; | ||||||||||||||||||||||||||||
| 18 | 1 | my %D; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | our @EXPORT = qw(year2en); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | BEGIN { *DEBUG = sub () {0} unless defined &DEBUG } # setup a DEBUG constant | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | #-------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | @DD{ '00' .. '09' } = @DD{ '0' .. '9' } = @D{ '0' .. '9' } | ||||||||||||||||||||||||||||
| 27 | 1 | = @OhDD{ '0' .. '9' } | |||||||||||||||||||||||||||
| 28 | = qw(oh one two three four five six seven eight nine); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | @OhDD{ '00' .. '09' } = map "$Oh $_", @D{ '0' .. '9' }; | |||||||||||||||||||||||||||
| 31 | # Altho "oh oh" presumably is never used | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | for my $num ('10' .. '99') { | |||||||||||||||||||||||||||
| 34 | 90 | $OhDD{$num} = $DD{$num} = num2en($num); | |||||||||||||||||||||||||||
| 35 | 90 | DEBUG > 1 and print "$num = $DD{$num}\n"; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | #-------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 126 | ▶ | sub year2en ($) { | ||||||||||||||||||||||||||
|
Subroutine
year2en: called CC=24 SCAR=31.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 126 | my $y = $_[0]; | |||||||||||||||||||||||||||
| 42 | 126 | ▶ | return undef unless defined $y and length $y; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $y and length $y
MC/DC100%2/2
defined $y and length $y
defined $y
length $y
Truth table100%3/3
A and B
A= defined $yB= length $y
| |||||||||||||||||||||||||||||
| 43 | 124 | $y =~ s/,//g; | |||||||||||||||||||||||||||
| 44 | 124 | ▶ | if( $y =~ m/\d/ and $y =~ m/^(-?)(\d{1,5})$/s ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$y =~ /\d/ and $y =~ /^(-?)(\d{1,5})$/s
MC/DC100%2/2
$y =~ /\d/ and $y =~ /^(-?)(\d{1,5})$/s
$y =~ /\d/
$y =~ /^(-?)(\d{1,5})$/s
Truth table100%3/3
A and B
A= $y =~ /\d/B= $y =~ /^(-?)(\d{1,5})$/s
| |||||||||||||||||||||||||||||
| 45 | 121 | ▶ | my $neg = $1 ? "negative " : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 121 | local $_ = $2; | |||||||||||||||||||||||||||
| 47 | 121 | ▶ | return $Zero if $_ eq '0'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 120 | ▶ | return "$neg$DD{$_}" if $DD{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 99 | ▶ | m/^(..)000$/ and return "$neg$DD{$1} $T"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 97 | ▶ | if( m/^.0...$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | # A family of troublesome cases: things like "60123". | ||||||||||||||||||||||||||||
| 54 | # We can't say "sixty one twenty-three" because that sounds | ||||||||||||||||||||||||||||
| 55 | # just like sixty-one twenty-three. So we special-case this | ||||||||||||||||||||||||||||
| 56 | # whole group. | ||||||||||||||||||||||||||||
| 57 | 15 | ▶ | m/^(.0)000$/ and return "$neg$DD{$1} $T"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 15 | ▶ | m/^(.0)00(.)$/ and return "$neg$DD{$1} $T $D{$2}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 12 | ▶ | m/^(.0)0(..)$/ and return "$neg$DD{$1} $T $DD{$2}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 8 | ▶ | m/^(.0)(.)00$/ and return "$neg$DD{$1} $T $D{$2} $H"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 6 | ▶ | m/^(.0)(.)(..)$/ and return "$neg$DD{$1} $T $D{$2} $OhDD{$3}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | DEBUG and print "Falling thru with x0,xxx number $_ !\n"; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 82 | ▶ | m/^(.)000$/ and return "$neg$DD{$1} $T"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 80 | ▶ | m/^(..)00$/ and return "$neg$DD{$1} $H"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 78 | ▶ | m/^(.)00$/ and return "$neg$DD{$1} $H"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 75 | ▶ | m/^(..)00(.)$/ and return "$neg$DD{$1} $Oh $Oh $DD{$2}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 74 | ▶ | m/^(..)0(..)$/ and return "$neg$DD{$1} $Oh $DD{$2}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 68 | ▶ | m/^(.)00(.)$/ and return "$neg$DD{$1} $T $DD{$2}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | #m/^(..)00(.)$/ and return "$neg$DD{$1} $T $DD{$2}"; | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 65 | ▶ | m/^(..)(.)(..)$/ and return "$neg$OhDD{$1} $D{$2} $OhDD{$3}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 34 | ▶ | m/^(..)(..)$/ and return "$neg$OhDD{$1} $OhDD{$2}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 13 | ▶ | m/^(.)(..)$/ and return "$neg$OhDD{$1} $OhDD{$2}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Else fallthru: | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 3 | if(DEBUG) { | |||||||||||||||||||||||||||
| 83 | my $x = num2en($y); | ||||||||||||||||||||||||||||
| 84 | print "Using superclass to return numerification \"$x\".\n"; | ||||||||||||||||||||||||||||
| 85 | return $x; | ||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||
| 87 | 3 | return num2en($y); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | #-------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 1 | 1; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||